diff --git a/VERSIONHISTORY.md b/VERSIONHISTORY.md index cb1fd617fb6..09a53ca5d0f 100644 --- a/VERSIONHISTORY.md +++ b/VERSIONHISTORY.md @@ -1,5 +1,30 @@ # Version History +## V5.8.2 + +V5.8.2 stops validation throwing on a string that is not well-formed text, lets a generation set the match limit of its regular expressions, and gives generated types `ApplyDefaults()`, read-only collections for arrays and JSON Patch support. It also fixes a number of smaller issues from the backlog. + +### Bug fixes + +- **A string that is not well-formed text is not valid, and never makes validation throw.** The parser accepts a string that holds the escape of half of a surrogate pair, such as `"\ud800"`, or bytes that are not UTF-8, and such text is checked only when it is read, so documents that are never read pay nothing. `pattern`, `minLength`, `maxLength`, `enum`, `const`, an asserted `format` and the keywords applied to property names threw `InvalidOperationException` for it, in the runtime evaluator, in V5 generated types and in V4 generated code. A keyword that reads the string's characters now reports it as not valid, so a lone surrogate never matches a pattern. A keyword that compares it (`const`, `enum`, `uniqueItems`, property names) finds it equal only to the same text, and `JsonElement` equality does the same rather than throwing. Text the parser found all ASCII is not checked again. Other text is checked once, with a vectorised UTF-8 check, by a keyword that reads its characters. In V4 generated code a keyword that looks up a property by name can report an object with such a name as not valid, because System.Text.Json unescapes the names it compares. A debug assertion that fired when an escaped string was compared with a shorter one is corrected. See [#1021](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). +- **Generated `Clone()` returns the instance when it is already a clone,** as its documentation says. It copied every time. See [#927](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/927). +- **The V4 source generator tools give each file a hint name that carries a hash of its namespace,** so a generator that generates more than once no longer fails on two types of the same name in different namespaces. `Foo.g.cs` becomes `Foo.1a2b3c4d.g.cs`. See [#651](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/651). +- **`email` and `idn-email` have no limit on the local part or on the whole address,** as in the other ports. The only limit is the domain's. See [#1029](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1029). +- **JSON Patch and JSON Merge Patch can replace the root of a generated type's document.** Replacing the root threw `InvalidCastException` when the builder was not a `JsonDocumentBuilder`. +- **`corvusjson jsonschema --help` renders again.** The description of `--nativeEnums` was read as markup. + +### New features + +- **The code generators set the match limit of the regular expressions they write.** `--regexMatchTimeout` (CLI), `regexMatchTimeout` (`generator-config.json`), `CorvusTextJsonRegexMatchTimeout` (V5 source generator) and `CorvusJsonSchemaRegexMatchTimeout` (V4 source generator) take a positive number of milliseconds, or -1 for none. The default stays 1,000. See [#1022](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1022). +- **Generated mutable types have `ApplyDefaults()`.** It adds each absent property that has a schema default to the document, with the default as its value, and does the same inside each property whose type has properties of its own. It changes the data, for sending to systems that do not apply the schema's defaults themselves. See [#953](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/953). +- **JSON Patch applies to the mutable element of a generated type.** `TryApplyPatch` and `TryValidateAndApplyPatch` have generic overloads for any `MySchema.Mutable`. See [#943](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/943). +- **Generated array types are read-only collections of their items.** A type whose only core type is array, and which is not a tuple, implements `IReadOnlyCollection` of its item type, and its public `GetEnumerator()` lets `foreach` run over it without allocating on .NET (on .NET Framework it allocates what `EnumerateArray()` does). See [#1049](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1049). + +### Other changes + +- The TypeScript and Rust test suite runners check the 73 leap-second cases, and the documents say which exclusions each runner makes. See [#988](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/988) and [#987](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/987). +- The regular expression translator pages describe where the translation is still used since V5.8.0, and the pattern conformance page records that TypeScript keeps the host's `RegExp` ([#1026](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1026)). + ## V5.8.1 V5.8.1 fixes a property lookup that could go stale in a `JsonDocumentBuilder`, and a JSONata string that was escaped twice when it was placed in an object or array. It also brings the JSONata implementation up to date with the official test suite and fixes the cases where it answered differently. diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Mutable.cs index 8a75125e6db..05909ad1f82 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.AixPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Name.cs index 4ed83dfd6dd..4e876e03e8d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.VersionsEntity.cs index fa79e5038ef..6f7a9169a7a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.cs index 18bbb5939dd..007f5d9f132 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.cs index c54fb39daf8..7f759b68677 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AixPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public AixPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Mutable.cs index f2d306978bf..a44b187a45c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Name.cs index 057914a6bc7..f4918e94a5f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.VersionsEntity.cs index c1927c72f1d..2bf30fb9745 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.cs index 1f229889c9f..9bca5416601 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.cs index ee7af4bab9b..b9d1567d6c9 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AlpinePlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public AlpinePlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Mutable.cs index 99a5b7eee83..61af3e9a022 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Name.cs index 503591f8d5b..01a6a2fe7b6 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.VersionsEntity.cs index 00ba55d109e..e7c5de44fc7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.cs index 754cbcd42b9..e0872b34b28 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.cs index edcb2420040..53fcd67784c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonLinuxPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public AmazonLinuxPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Mutable.cs index 34dc1bdc8b0..091ab57b463 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Name.cs index ed5e4600641..066b5910f8e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.VersionsEntity.cs index 48ef419e4b3..ff6cc9c3385 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.cs index 93f96c31286..22015491754 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.cs index 04e2bbfb23a..9fbfb6dc83f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AmazonPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public AmazonPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Mutable.cs index a914f73b2c5..11c2e23c18b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.AosPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Name.cs index 35efc172887..16c7b896024 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.VersionsEntity.cs index aee9ba8f789..3db244eea47 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.cs index 9df92ece1bd..6e0bef581b8 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.cs index d05d5c97792..4f24829670c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.AosPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public AosPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Mutable.cs index ad08fa3d155..aad77309d6a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Name.cs index 87cefdda7e8..e647649516b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.VersionsEntity.cs index 8eb0d0d577a..ec6a0ff9254 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.cs index 9d505b6f5f1..ae29405bdfc 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.cs index 95bbb390d45..213be469d68 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ArchLinuxPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public ArchLinuxPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Mutable.cs index 751cac7436e..cbae193ad90 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Name.cs index 2d39efc67a6..948d29f2ccf 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.VersionsEntity.cs index 8d6a6920fa1..8135bcde78c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.cs index f95fbcb4471..3dd86ed90f7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.cs index 7ddfd67e95c..2e788cb9278 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ClearLinuxPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public ClearLinuxPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.CollectionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.CollectionsEntity.cs index 80176fa1049..435031c8524 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.CollectionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.CollectionsEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public CollectionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.cs index 4ba2e7bac6c..7d2eb705529 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Collections.cs @@ -21,11 +21,13 @@ public readonly partial struct AnsibleMetaSchema public readonly partial struct Collections #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public Collections Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.JsonStringArray.cs index 53bfd3961b4..94a5b460baa 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ComplexConditional public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.cs index 0dbc68b655e..9547af427c4 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ComplexConditional.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public ComplexConditional Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Mutable.cs index eecce693829..11b1b623d33 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Name.cs index f617022cea1..9e600d932aa 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.VersionsEntity.cs index f98b25785a8..f256ade921b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.cs index 70c204cc6df..56803b5d25b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.cs index 48e25787de4..f7f9739bdc6 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.CumulusPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public CumulusPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Mutable.cs index 730958a55ff..2a2a199bf07 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.DebianPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Name.cs index b84080a5f6d..42f283eefb7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.VersionsEntity.cs index 08dea47789b..adee870cb6e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.cs index 57a3bbe1870..8b9367c983e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.cs index 56ab403f265..5ea9479886d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DebianPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public DebianPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Mutable.cs index 172daa8c2c8..1b7b7fc3f99 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Name.cs index 5f95d6514a6..cb9c9f2890d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.VersionsEntity.cs index 0ce33eeed44..b0dfcda5b19 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.cs index fad71e3421c..610641c42fe 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.cs index 874253d62c2..70a21ae677d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DellOsPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public DellOsPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Mutable.cs index d8f29472ab1..d1abf6ea4a6 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Mutable.cs @@ -932,6 +932,31 @@ public bool RemoveWhen() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.Mutable.cs index b2a524ebb4c..80e2217bce9 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.Mutable.cs @@ -300,6 +300,31 @@ public void SetName(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.cs index 6cf3073a5ec..110d388a74c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredName.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.Mutable.cs index 2e92acb7dde..2be7a54126e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.Mutable.cs @@ -300,6 +300,31 @@ public void SetRole(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.cs index d998b400e72..4c36939b598 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredRole.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRole Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.Mutable.cs index ce563186474..af22e808093 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.Mutable.cs @@ -300,6 +300,31 @@ public void SetSrc(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.cs index 3932d4c74db..4039593c28a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.RequiredSrc.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredSrc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Scm.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Scm.cs index 93c1c22b278..8969d051a7a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Scm.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Scm.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public Scm Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Tags.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Tags.cs index 50c33020c91..ca722956e72 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Tags.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.Tags.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public Tags Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.cs index 000fe4ae25a..fa005906329 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModel.cs @@ -573,6 +573,12 @@ private void CheckValidInstance() public DependencyModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModelArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModelArray.cs index a79e2edc4e8..015ef5a1953 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModelArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DependencyModelArray.cs @@ -21,11 +21,13 @@ public readonly partial struct AnsibleMetaSchema public readonly partial struct DependencyModelArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public DependencyModelArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Mutable.cs index 68f148fd3d1..82ec784aa0d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Name.cs index d23b86682c2..eda4320e2cb 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.VersionsEntity.cs index cf1c944bd3d..89bf460a6b6 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.cs index c1ff7e7a6cd..005ca2406c1 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.cs index 3e120ac8a8a..83108b4668d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DevuanPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public DevuanPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Mutable.cs index e409aebd1ce..4be098adcf5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Name.cs index 6c7e5b99858..0ae9796300e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.VersionsEntity.cs index e92e1c0a93c..8b5e7dacd33 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.cs index 549864624fe..172c793533a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.cs index d8d43d821ec..47605fc0eb9 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.DragonFlyBsdPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public DragonFlyBsdPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Mutable.cs index 6d2995096b0..a62684bbad3 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.ElPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Name.cs index 80f292187f2..7db5dc4b12f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.VersionsEntity.cs index dab0316d21d..692b4392b05 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.cs index 5d8c4be5b0d..ca5b3358f1a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.cs index da0b953b97d..1112b53e1f7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.ElPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public ElPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Mutable.cs index 24c48235fc5..ef5590270a4 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.EosPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Name.cs index ef4d47ac55e..1d30dbf0cea 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.VersionsEntity.cs index b3e9c9a8f61..3839262b77f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.cs index 72afa98bb29..9fdb74590eb 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.cs index 47cec75a6ce..14f554e117b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.EosPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public EosPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Mutable.cs index 28deb7fc2b8..c941628513b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Name.cs index 9c538eac19c..19cbce11747 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.VersionsEntity.cs index 50644be5b2c..b8a2e86d33d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.cs index a4a06ffeab7..0dcc8273dbe 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.cs index c234c5f03c9..e9297b0f9b1 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FedoraPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public FedoraPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Mutable.cs index c57472875cb..f19297b6b3f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Name.cs index 5954abdedb5..92e6650ba34 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.VersionsEntity.cs index 0f95ce2535a..e67a0f46508 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.cs index ae45d707bcc..06ca7c05f46 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.cs index 0c4b4dd8c40..9442be11696 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.FreeBsdPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public FreeBsdPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.Mutable.cs index 7c9daad71ff..ae2748ae63f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.Mutable.cs @@ -602,6 +602,31 @@ public bool RemoveMinAnsibleVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.Mutable.cs index f46bd271aea..c09ca3a1943 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.Mutable.cs @@ -560,6 +560,31 @@ public void SetMinAnsibleVersion(in Corvus.Text.Json.JsonElement.Sourc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.cs index 36624ed669a..9be79193558 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public RequiredAuthorAndDescriptionAndLicenseAndMinAnsibleVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.Mutable.cs index 65c6c299e48..efc34e8105a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveStandalone() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.StandaloneEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.StandaloneEntity.cs index 6d1e0d1386e..a60fd44648e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.StandaloneEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.StandaloneEntity.cs @@ -312,6 +312,12 @@ private void CheckValidInstance() public StandaloneEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.cs index 48c5bd2fa63..c365a12f1b9 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.WithStandaloneTrue.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithStandaloneTrue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.cs index 0e289a55b88..278f64013ea 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf0Entity.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public AllOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.Mutable.cs index 3972a6d83c8..b2bdd56c2e0 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.Mutable.cs @@ -311,6 +311,31 @@ public bool RemoveDescription() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.Mutable.cs index 193ff491d11..39fa26f8af5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.Mutable.cs @@ -302,6 +302,31 @@ public void SetDescription(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.Mutable.cs index 1b209c9c1c0..9cef9e4d598 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.Mutable.cs @@ -820,6 +820,31 @@ public void SetVideoLinks(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.cs index 3ebcde44ee8..2009a092e86 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.NotEntity.cs @@ -492,6 +492,12 @@ private void CheckValidInstance() public NotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.cs index cf16d35fb09..ab0f5ec7cf2 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.RequiredDescription.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredDescription Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.Mutable.cs index 5d03cd0d1f3..f23e79e10f6 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveStandalone() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.StandaloneEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.StandaloneEntity.cs index f6f1ad0273d..90a0457444d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.StandaloneEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.StandaloneEntity.cs @@ -312,6 +312,12 @@ private void CheckValidInstance() public StandaloneEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.cs index 01b408f115e..f5eabe7bc4a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.WithStandaloneFalse.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithStandaloneFalse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.cs index 762befa7ced..427ff93c0de 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.AllOf1Entity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.JsonStringArray.cs index 1abe6b3424f..38dfc77db63 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GalaxyInfoModel public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.Mutable.cs index 50f50008492..8a0d98c4267 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.Mutable.cs @@ -1251,6 +1251,31 @@ public bool RemoveVideoLinks() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.NamespaceName.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.NamespaceName.cs index 7fd4025933a..12cce51d548 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.NamespaceName.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.NamespaceName.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public NamespaceName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.Mutable.cs index 1bc2dad9a04..8e94f0257c8 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.Mutable.cs @@ -300,6 +300,31 @@ public void SetDescription(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.cs index 68cf89f8951..f878d10de58 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RequiredDescription.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredDescription Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RoleName.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RoleName.cs index 864c10c6269..1124d508429 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RoleName.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.RoleName.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public RoleName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.cs index 838551bf761..5d15f1e489f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GalaxyInfoModel.cs @@ -559,6 +559,12 @@ private void CheckValidInstance() public GalaxyInfoModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Mutable.cs index ab0caac1a52..1e642fe8a27 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Name.cs index c5535b9915d..43d3d2da9b2 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.VersionsEntity.cs index dd31606dc7f..47057c220dc 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.cs index 62273da4a07..01c9eeeed2a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.cs index 5b1e28afe99..d29ee72621b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericBsdPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public GenericBsdPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Mutable.cs index 2a8df45582c..55d5a656ae8 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Name.cs index 6bddcc37e24..ee513f09479 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.VersionsEntity.cs index bbb35724162..7123f805fb8 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.cs index df3bea8f251..e8aaa47432c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.cs index b158590f022..83721969bf9 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericLinuxPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public GenericLinuxPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Mutable.cs index 22075586ec8..916c8c0773f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Name.cs index dc69e83f790..81d8c5cbbf5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.VersionsEntity.cs index e8595653b09..a5cfca1f6d7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.cs index 50bbd8f2ade..4503ecb6d09 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.cs index fe2c3b80bd4..20da1a47b98 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GenericUnixPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public GenericUnixPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Mutable.cs index a0ed5a55ca2..a7d4085aabe 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.GentooPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Name.cs index 6b1178d292e..183ac79c1d2 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.VersionsEntity.cs index 803da8d0390..87abd6a7963 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.cs index c60c972759b..a3093bdba4d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.cs index 743ad959774..58f25718e13 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.GentooPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public GentooPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Mutable.cs index dc3e24d174e..611c7c1d5c7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Name.cs index 500d7bd0841..d50b5f2617c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.VersionsEntity.cs index df9396e474a..b231ba1bb31 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.cs index 5e5652051dd..f4a7f225097 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.cs index 1c5445dfce1..7baee9446bd 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.HardenedBsdPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public HardenedBsdPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Mutable.cs index 76715154b83..68a3d4a753e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.IosPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Name.cs index cbd38783e47..29543dd30c1 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.VersionsEntity.cs index 00c1bf421b9..cfc5092eab7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.cs index 992c655e387..6c24190f968 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.cs index d4058ce92ca..e2e466babff 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.IosPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public IosPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Mutable.cs index f6bb76f9d3c..f30d0cf839f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.JunosPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Name.cs index 5b25ce263d2..9eacd791628 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.VersionsEntity.cs index 29f99cf7a52..10a908b983f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.cs index 7593ebb6e43..31bebfd5f3f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.cs index 4d2045f9b8b..aada6e77d7e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.JunosPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JunosPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Mutable.cs index b142ea112a4..2371ba551bb 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.KaliPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Name.cs index 24ef13ad32f..4602b02683b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.VersionsEntity.cs index 2288f696102..5e465f9d0fd 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.cs index a1ce12fa752..2aa353753fc 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.cs index 32deab4df01..aaaedf711ec 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.KaliPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public KaliPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Mutable.cs index c9bfc1b714b..d076477f969 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Name.cs index 282a9427b09..27c7aef2a62 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.VersionsEntity.cs index 3116ac591e5..4adc59b4b1d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.cs index 22e05f41a1f..f84246024b1 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.cs index 30213e6c7ac..26fb3bb6ea6 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public MacOsPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Mutable.cs index 64a10875630..df68c1d52ba 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Name.cs index 1addc114c8a..3cc8433b021 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.VersionsEntity.cs index 5500c3a41da..1fc6e77b43c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.cs index 0089054e3d0..02d5aded3fb 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.cs index 85721f71cc1..0eb72b53c40 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MacOsxPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public MacOsxPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Mutable.cs index 43ae9f9f5f5..c8e74a49ead 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Name.cs index c92e712406c..af232a77fb7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.VersionsEntity.cs index c363fd773fe..f21eb405b1e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.cs index 173519d8aa9..6401217a87c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.cs index 1e1dd66f65e..cd76f660244 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.MageiaPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public MageiaPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Mutable.cs index 31c92aa786f..9cef29fd31c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Mutable.cs @@ -579,6 +579,37 @@ public bool RemoveGalaxyInfo() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GalaxyInfoUtf8, out Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.GalaxyInfoModel.Mutable __corvusGalaxyInfo)) + { + __corvusGalaxyInfo.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Mutable.cs index b649d0e6091..66767d75a29 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Name.cs index 5d1be7fe036..f3506046e8b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.VersionsEntity.cs index 7d0420aa686..a5a8a71ce88 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.cs index a0671e23973..0a116eefc96 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.cs index 3a30f95358f..93f659ec9fe 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NetBsdPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public NetBsdPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Mutable.cs index 139abafa4d5..af0c47c36e5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.NxosPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Name.cs index 3bff3162d82..6741e29f04b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.VersionsEntity.cs index 8f207753e11..379717c87f5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.cs index c530e529be3..87f09be799c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.cs index 5e5c03e3258..7220fd84ea4 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.NxosPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public NxosPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Mutable.cs index 302033d7f5a..8ca1096666b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Name.cs index f45730402a4..9b6eadfd1bf 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.VersionsEntity.cs index b8771049503..58729882224 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.cs index d4deb8c625b..c7c089c4828 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.cs index 9ffd6c70e79..6b0bac365d7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenBsdPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public OpenBsdPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Mutable.cs index c80c9c3f343..e0460e372df 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Name.cs index 94dbf9707c1..32b76df2e59 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.VersionsEntity.cs index 41795812f2e..1ed287e96ea 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.cs index eca0fa73742..6c1cb9c76bc 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.cs index 6be47cd1704..2dae2821468 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpenWrtPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public OpenWrtPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Mutable.cs index 38b82e8e6ef..aa40ba7d723 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Name.cs index f6491435850..e3a8c2baccd 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.VersionsEntity.cs index e5c0bae2490..195b740b02b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.cs index 7aee1f220e9..220edf7ac1d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.cs index 500aadfb879..12882baaba3 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OpensusePlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public OpensusePlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Mutable.cs index 384e34f34c3..601ef926cda 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Name.cs index 307f0529a0e..93fa5ec4c94 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.VersionsEntity.cs index e1bb32c1fea..e6c83e2b682 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.cs index 186e19a850a..e0228e66f81 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.cs index 5670b70adf9..5bd4e081a17 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.OracleLinuxPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public OracleLinuxPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Mutable.cs index 94d8cc3f1a4..afd1ad2ebdf 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.Os10PlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Name.cs index 54cfdd1e053..350172ebda7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.VersionsEntity.cs index 96f13e6b6af..898deafe113 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.cs index 942dcdc32c0..957d63d0e6c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.cs index 25aaba85d5a..e7c9d8a6e31 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Os10PlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public Os10PlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Mutable.cs index 90e3ec6417b..15d473efff2 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Name.cs index d40f1ca37fb..50a9f63bd18 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.VersionsEntity.cs index 2c1920fdf1e..d93a4bf04d5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.cs index 3845a3bf6e8..54d7cffe8d7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.cs index 2995a14f897..41dfd400765 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.PanOsPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public PanOsPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.PlatformsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.PlatformsEntity.cs index c174dfc06d9..d948f57f8cd 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.PlatformsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.PlatformsEntity.cs @@ -1556,6 +1556,12 @@ private void CheckValidInstance() public PlatformsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.cs index bc7e12c676b..25d669b2554 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.Platforms.cs @@ -21,11 +21,13 @@ public readonly partial struct AnsibleMetaSchema public readonly partial struct Platforms #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public Platforms Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Mutable.cs index ec5ec2f360d..10a18aff265 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.SlesPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Name.cs index 72880f99b9d..293a9e1a855 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.VersionsEntity.cs index 4df5a3dbfda..9e0d981a35c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.cs index 01e36eafb7d..5958488dcae 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.cs index 4403e06a805..5b9421ef370 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SlesPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public SlesPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Mutable.cs index 5b4f4277395..9f25d35b394 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Name.cs index 24803b6fd2a..ba695b86b8c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.VersionsEntity.cs index 8cec7d7d10d..0d2b400970c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.cs index 31401f28a25..9a8fcc4092d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.cs index 671d58b6739..01c29cda521 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SmartOsPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public SmartOsPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Mutable.cs index 58f95ac6b7e..a1bd80ba925 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Name.cs index cc952eef78f..193dcc46a0c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.VersionsEntity.cs index bd15fa6b3ac..4b2740df41f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.cs index ea248871246..5f67e4fc5c8 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.cs index 26141eb34f0..a54b350cf95 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SolarisPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public SolarisPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Mutable.cs index 6532bd00685..25062922077 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Name.cs index d482daffd13..2b49ddd80e6 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.VersionsEntity.cs index 637cb3b59d7..962f61f4bac 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.cs index 4637faee473..8d06a52e030 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.cs index f8ed2e1974f..4208d04742a 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.SynologyPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public SynologyPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Mutable.cs index 32bcfcf6d11..12eed2c6055 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.TmosPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Name.cs index 18f6005e184..e7071b5bd97 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.VersionsEntity.cs index 4c997588118..a9124aab888 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.cs index 6c9724c6223..8d88526556b 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.cs index aeaa051ad34..70ad6cfa974 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.TmosPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public TmosPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Mutable.cs index 6cab793cdd4..e599ff19f9f 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Name.cs index 01b1d8d178e..aed48fb5f04 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.VersionsEntity.cs index 4e0830c70d7..a72ce4b27db 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.cs index 9a523904f06..ffa144c7ef5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.cs index 240b1401301..164c5d7cbbb 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.UbuntuPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public UbuntuPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Mutable.cs index b50b85f8ae1..99bc2b65136 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Name.cs index e5c0d466b45..c31e70b6911 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.VersionsEntity.cs index f01f7be8140..cec390cd4d3 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.cs index feac2be118b..16bd467de23 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.cs index abc5accbd35..2f867242d3d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VCenterPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public VCenterPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Mutable.cs index 2ea8d17393d..754dddd6eea 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Name.cs index bd4d193494c..18b04a94d06 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.VersionsEntity.cs index b9039dfad82..f9ac4747a20 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.cs index 8c10c72c2ee..f8f0006b517 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.cs index 645fc79c070..a6c06941568 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VSpherePlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public VSpherePlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Mutable.cs index 5b1fa056415..f024b27fed2 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Name.cs index fa1acb7d9a5..dabfa1cbfbc 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.VersionsEntity.cs index 35533c1d7ec..3dae9e48e3e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.cs index 2688efb2050..5b8c1a97b2d 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.cs index 3d3949e2870..aede6048725 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.VoidLinuxPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public VoidLinuxPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Mutable.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Mutable.cs index 717f56956eb..e020a307f05 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Mutable.cs @@ -371,6 +371,36 @@ public bool RemoveVersions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out IJsonDocument? _, out int _)) + { + SetVersions(Corvus.AnsibleMetaBenchmark.Current.AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Name.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Name.cs index 4c7263582d0..eb58cab0ee7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Name.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.Name.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.VersionsEntity.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.VersionsEntity.cs index 95003d05d5d..d5deb17eea5 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.VersionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.VersionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public VersionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.cs index 163d7687aaf..fe68a0a5804 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.VersionsArray.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public VersionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.cs index a3dea01b50e..7a4e20bca07 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.WindowsPlatformModel.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public WindowsPlatformModel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.cs index f9797194069..6dcaf2fc1eb 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/AnsibleMetaSchema.cs @@ -431,6 +431,12 @@ private void CheckValidInstance() public AnsibleMetaSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonArray.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonArray.cs index e7d165da968..c38130f22be 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonArray.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonArray.cs @@ -18,11 +18,13 @@ namespace Corvus.AnsibleMetaBenchmark.Current; public readonly partial struct JsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -67,6 +69,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -280,6 +297,12 @@ private void CheckValidInstance() public JsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonBoolean.cs index 4d14f2653cd..bfaf93624d7 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonObject.cs index a92d031c9c8..57ec2e7f83c 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonString.cs index f4973884196..19a83bf6d3e 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/corvusjson-jsonschema.lock index 54295e0a49f..84c2060fef8 100644 --- a/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.AnsibleMetaBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:12.6512546\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:37.4112840\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.AppEntity.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.AppEntity.cs index 1e0f4569e94..c1b25757132 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.AppEntity.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.AppEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AppEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.Mutable.cs index 1e952f80b21..cce173b9b47 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.Mutable.cs @@ -586,6 +586,37 @@ public bool RemoveWatch() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchUtf8, out Corvus.AwsCdkBenchmark.Current.AwsCdkSchema.WatchEntity.Mutable __corvusWatch)) + { + __corvusWatch.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.IncludeJsoArray.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.IncludeJsoArray.cs index 35c36837215..9972a1f21e7 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.IncludeJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.IncludeJsoArray.cs @@ -23,11 +23,13 @@ public readonly partial struct WatchEntity public readonly partial struct IncludeJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public IncludeJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.JsonStringArray.cs index 7a1f94b83b7..a3cdd5dc999 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct WatchEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.Mutable.cs index bf3dfbfcae4..003c0b44e03 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.Mutable.cs @@ -406,6 +406,31 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.cs index 7cbf284b7ea..d3cb96e663f 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.WatchEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public WatchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.cs index 1c7c0c520f5..dae2d381c16 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/AwsCdkSchema.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public AwsCdkSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonBoolean.cs index d43bdc748e3..14d9c32a808 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonObject.cs index 84d7756ee46..2de414386f5 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonString.cs index 4000cc4d30f..6239cce4c53 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/corvusjson-jsonschema.lock index 50aeb782cbc..6ed16b75583 100644 --- a/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.AwsCdkBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:13.5388451\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:39.1548689\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.EnvEntity.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.EnvEntity.cs index 7e874ef5966..344d521c5f4 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.EnvEntity.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.EnvEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public EnvEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.Mutable.cs index b4b36f73bae..122a06e0b74 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.Mutable.cs @@ -314,6 +314,36 @@ public bool RemoveEnv() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnvUtf8, out IJsonDocument? _, out int _)) + { + SetEnv(Corvus.BabelrcBenchmark.Current.BabelrcSchema.AllOf1Entity.EnvEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.cs index b9382b519f1..1daea8cc8eb 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.AllOf1Entity.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Mutable.cs index c04fea6d81a..e424acb9da5 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Mutable.cs @@ -2111,6 +2111,86 @@ public bool RemoveSourceRoot() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AstUtf8, out IJsonDocument? _, out int _)) + { + SetAst(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.IncludeTheAstInTheReturnedObject.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CodeUtf8, out IJsonDocument? _, out int _)) + { + SetCode(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.EnableCodeGeneration.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommentsUtf8, out IJsonDocument? _, out int _)) + { + SetComments(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.OutputCommentsInGeneratedOutput.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompactUtf8, out IJsonDocument? _, out int _)) + { + SetCompact(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.CompactEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnvUtf8, out IJsonDocument? _, out int _)) + { + SetEnv(Corvus.BabelrcBenchmark.Current.BabelrcSchema.AllOf1Entity.EnvEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilenameUtf8, out IJsonDocument? _, out int _)) + { + SetFilename(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.FilenameForUseInErrorsEtc.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputSourceMapUtf8, out IJsonDocument? _, out int _)) + { + SetInputSourceMap(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.InputSourceMapEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.KeepModuleIdExtensionsUtf8, out IJsonDocument? _, out int _)) + { + SetKeepModuleIdExtensions(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.KeepExtensionsInModuleIds.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModuleIdsUtf8, out IJsonDocument? _, out int _)) + { + SetModuleIds(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.ModuleIdsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RetainLinesUtf8, out IJsonDocument? _, out int _)) + { + SetRetainLines(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.RetainLinesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SourceMapsUtf8, out IJsonDocument? _, out int _)) + { + SetSourceMaps(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.SourceMapsEntity.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.CompactEntity.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.CompactEntity.cs index fcd5e5d757c..8d55608ac39 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.CompactEntity.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.CompactEntity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public CompactEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.EnableCodeGeneration.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.EnableCodeGeneration.cs index e34c06cf4cf..a4c30be8d38 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.EnableCodeGeneration.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.EnableCodeGeneration.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableCodeGeneration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.FilenameForUseInErrorsEtc.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.FilenameForUseInErrorsEtc.cs index 21fd209dfe0..fa8226385a5 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.FilenameForUseInErrorsEtc.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.FilenameForUseInErrorsEtc.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public FilenameForUseInErrorsEtc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.IncludeTheAstInTheReturnedObject.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.IncludeTheAstInTheReturnedObject.cs index 079f860a788..3c980489965 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.IncludeTheAstInTheReturnedObject.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.IncludeTheAstInTheReturnedObject.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IncludeTheAstInTheReturnedObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.InputSourceMapEntity.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.InputSourceMapEntity.cs index 1428a277876..648995721b2 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.InputSourceMapEntity.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.InputSourceMapEntity.cs @@ -396,6 +396,12 @@ private void CheckValidInstance() public InputSourceMapEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.KeepExtensionsInModuleIds.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.KeepExtensionsInModuleIds.cs index 1b3a8dc01d7..417d4507ea1 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.KeepExtensionsInModuleIds.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.KeepExtensionsInModuleIds.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public KeepExtensionsInModuleIds Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.ModuleIdsEntity.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.ModuleIdsEntity.cs index de27ba4fc4e..ddd5c0391f8 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.ModuleIdsEntity.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.ModuleIdsEntity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public ModuleIdsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.Mutable.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.Mutable.cs index 9ad49032f10..f1dc0156317 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.Mutable.cs @@ -1976,6 +1976,81 @@ public bool RemoveSourceRoot() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AstUtf8, out IJsonDocument? _, out int _)) + { + SetAst(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.IncludeTheAstInTheReturnedObject.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CodeUtf8, out IJsonDocument? _, out int _)) + { + SetCode(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.EnableCodeGeneration.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommentsUtf8, out IJsonDocument? _, out int _)) + { + SetComments(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.OutputCommentsInGeneratedOutput.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompactUtf8, out IJsonDocument? _, out int _)) + { + SetCompact(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.CompactEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilenameUtf8, out IJsonDocument? _, out int _)) + { + SetFilename(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.FilenameForUseInErrorsEtc.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputSourceMapUtf8, out IJsonDocument? _, out int _)) + { + SetInputSourceMap(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.InputSourceMapEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.KeepModuleIdExtensionsUtf8, out IJsonDocument? _, out int _)) + { + SetKeepModuleIdExtensions(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.KeepExtensionsInModuleIds.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModuleIdsUtf8, out IJsonDocument? _, out int _)) + { + SetModuleIds(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.ModuleIdsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RetainLinesUtf8, out IJsonDocument? _, out int _)) + { + SetRetainLines(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.RetainLinesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SourceMapsUtf8, out IJsonDocument? _, out int _)) + { + SetSourceMaps(Corvus.BabelrcBenchmark.Current.BabelrcSchema.Options.SourceMapsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OnlyArray.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OnlyArray.cs index b9086215f15..0e3a60c2cc7 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OnlyArray.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OnlyArray.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public OnlyArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OppositeOfTheOnlyOption.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OppositeOfTheOnlyOption.cs index 205b8d0c9da..34740deb5fe 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OppositeOfTheOnlyOption.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OppositeOfTheOnlyOption.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public OppositeOfTheOnlyOption Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OutputCommentsInGeneratedOutput.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OutputCommentsInGeneratedOutput.cs index b7a08920895..e940b726b64 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OutputCommentsInGeneratedOutput.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.OutputCommentsInGeneratedOutput.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public OutputCommentsInGeneratedOutput Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.PluginsArray.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.PluginsArray.cs index aa58aec25e4..07014a2632f 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.PluginsArray.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.PluginsArray.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public PluginsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.cs index ef33ee62b5d..981bbc517da 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PluginsArrayArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Options public readonly partial struct PluginsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public PluginsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.PresetsArray.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.PresetsArray.cs index 655de6b998a..5e6aa2172bd 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.PresetsArray.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.PresetsArray.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public PresetsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.cs index 626cdd9a30a..65caadbf873 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.PresetsArrayArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Options public readonly partial struct PresetsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public PresetsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.RetainLinesEntity.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.RetainLinesEntity.cs index c550bafb04b..dd57cec3e37 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.RetainLinesEntity.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.RetainLinesEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RetainLinesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.SourceMapsEntity.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.SourceMapsEntity.cs index 1b419e25457..34c82688881 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.SourceMapsEntity.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.SourceMapsEntity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public SourceMapsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.cs index f9527ae216f..b51738370a7 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.Options.cs @@ -843,6 +843,12 @@ private void CheckValidInstance() public Options Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.cs index 5431cbf1d72..96d61fc57f5 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/BabelrcSchema.cs @@ -897,6 +897,12 @@ private void CheckValidInstance() public BabelrcSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonBoolean.cs index 784bf91b81b..291b24a90dc 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonObject.cs index 81780897802..38737d2d9f5 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonString.cs index 1516a827478..c479393f34d 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/corvusjson-jsonschema.lock index 1ff9c1d6719..0359233c1c3 100644 --- a/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.BabelrcBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:14.4504794\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:41.5383650\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Age.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Age.cs index 2abfd0f8a12..cd50be2f045 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Age.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Age.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public Age Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/CompetedInYears.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/CompetedInYears.cs index 05d14487453..f1c03d03c84 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/CompetedInYears.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/CompetedInYears.cs @@ -18,11 +18,13 @@ namespace Corvus.PersonBenchmark.Current; public readonly partial struct CompetedInYears #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -100,6 +102,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -313,6 +330,12 @@ private void CheckValidInstance() public CompetedInYears Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonInt32.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonInt32.cs index 3e475274263..921d3b315c2 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonInt32.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.Mutable.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.Mutable.cs index 46c4ce5e939..dcc77a35623 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.Mutable.cs @@ -474,6 +474,37 @@ public void SetName(in Corvus.PersonBenchmark.Current.PersonName.Sourc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NameUtf8, out Corvus.PersonBenchmark.Current.PersonName.Mutable __corvusName)) + { + __corvusName.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.cs index 51ac4887f57..85d1b6fcd6b 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/JsonObject.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponent.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponent.cs index 942bad84f27..6c02d86efa4 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponent.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponent.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public NameComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponentArray.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponentArray.cs index a8fc48f7c03..464e1d4fbe2 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponentArray.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/NameComponentArray.cs @@ -18,11 +18,13 @@ namespace Corvus.PersonBenchmark.Current; public readonly partial struct NameComponentArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public NameComponentArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/OtherNames.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/OtherNames.cs index 5bcf1a4b67d..874ec46f5e6 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/OtherNames.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/OtherNames.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public OtherNames Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.Mutable.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.Mutable.cs index a54fa6fd2dc..f8d9791cc68 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.Mutable.cs @@ -383,6 +383,37 @@ public void SetName(in Corvus.PersonBenchmark.Current.PersonName.Sourc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NameUtf8, out Corvus.PersonBenchmark.Current.PersonName.Mutable __corvusName)) + { + __corvusName.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.cs index e9260249f44..741c8768c3f 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/Person.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Person Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.Mutable.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.Mutable.cs index fa6dc317a1c..5322e87286a 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.Mutable.cs @@ -432,6 +432,31 @@ public bool RemoveOtherNames() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.cs b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.cs index 14c3e0e6e67..0048a39493d 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.cs +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/PersonName.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public PersonName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/corvusjson-jsonschema.lock index 7d781d30c89..0c56ea6cc22 100644 --- a/benchmarks/Corvus.Text.Json.BenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.BenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:15.3209847\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:43.3422906\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignAfterOpenBracketEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignAfterOpenBracketEntity.cs index 45b097cefb3..80e0600fa18 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignAfterOpenBracketEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignAfterOpenBracketEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AlignAfterOpenBracketEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignArrayOfStructuresEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignArrayOfStructuresEntity.cs index b150a4c1312..0935904e1e5 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignArrayOfStructuresEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignArrayOfStructuresEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AlignArrayOfStructuresEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.Mutable.cs index 2b9a54070d4..6e160d75949 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.Mutable.cs @@ -544,6 +544,31 @@ public bool RemovePadOperators() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.cs index 865abf36592..83fc43adbfd 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat15AlignmentOptions.cs @@ -451,6 +451,12 @@ private void CheckValidInstance() public ClangFormat15AlignmentOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat38StyleOfAligningConsecutiveAssignments.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat38StyleOfAligningConsecutiveAssignments.cs index 6be2885702a..f84b0a2a22f 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat38StyleOfAligningConsecutiveAssignments.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.ClangFormat38StyleOfAligningConsecutiveAssignments.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ClangFormat38StyleOfAligningConsecutiveAssignments Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.cs index b3541852c76..5156527bf04 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveAssignmentsEntity.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public AlignConsecutiveAssignmentsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat11StyleOfAligningConsecutiveBitFields.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat11StyleOfAligningConsecutiveBitFields.cs index 7ec6a20a44d..a5ee8aaaf83 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat11StyleOfAligningConsecutiveBitFields.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat11StyleOfAligningConsecutiveBitFields.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ClangFormat11StyleOfAligningConsecutiveBitFields Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.Mutable.cs index 0756a3f1c58..8ed23b4b406 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.Mutable.cs @@ -412,6 +412,31 @@ public bool RemoveEnabled() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.cs index 65cc1102e20..14a5b6d172b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.ClangFormat15AlignmentOptions.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ClangFormat15AlignmentOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.cs index 53a46b8a296..e39ff25fe53 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveBitFieldsEntity.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public AlignConsecutiveBitFieldsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.Mutable.cs index d61f28d8d3f..d6e51a7fef3 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.Mutable.cs @@ -412,6 +412,31 @@ public bool RemoveEnabled() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.cs index 030bbc5c212..74dc308e145 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat15AlignmentOptions.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ClangFormat15AlignmentOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat38StyleOfAligningConsecutiveDeclarations.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat38StyleOfAligningConsecutiveDeclarations.cs index c0ab5943a23..82fe95ecd05 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat38StyleOfAligningConsecutiveDeclarations.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.ClangFormat38StyleOfAligningConsecutiveDeclarations.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ClangFormat38StyleOfAligningConsecutiveDeclarations Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.cs index 2fce9bddf84..c30866aad29 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveDeclarationsEntity.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public AlignConsecutiveDeclarationsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.Mutable.cs index 6863efe65db..d6ba7de3acb 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.Mutable.cs @@ -412,6 +412,31 @@ public bool RemoveEnabled() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.cs index 84b762804c1..6103cd53c66 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat15AlignmentOptions.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ClangFormat15AlignmentOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat9StyleOfAligningConsecutiveMacros.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat9StyleOfAligningConsecutiveMacros.cs index bbc9a21a6fe..136c180a9d5 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat9StyleOfAligningConsecutiveMacros.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.ClangFormat9StyleOfAligningConsecutiveMacros.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ClangFormat9StyleOfAligningConsecutiveMacros Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.cs index d8d34b35531..05a8828fc3f 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignConsecutiveMacrosEntity.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public AlignConsecutiveMacrosEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignEscapedNewlinesEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignEscapedNewlinesEntity.cs index cd6fa3ebe8a..d1de268d08a 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignEscapedNewlinesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignEscapedNewlinesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AlignEscapedNewlinesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignOperandsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignOperandsEntity.cs index 41eb6ec593b..531730d68b2 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignOperandsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignOperandsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AlignOperandsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.HowManyEmptyLinesToApplyAlignment.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.HowManyEmptyLinesToApplyAlignment.cs index 5034a0db7f3..e371f4d608b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.HowManyEmptyLinesToApplyAlignment.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.HowManyEmptyLinesToApplyAlignment.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public HowManyEmptyLinesToApplyAlignment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.Mutable.cs index 9631cbfba78..f4b4d3a80e2 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.Mutable.cs @@ -346,6 +346,31 @@ public bool RemoveOverEmptyLines() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.SpecifiesTheWayToAlignTrailingComments.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.SpecifiesTheWayToAlignTrailingComments.cs index 7e5d617bf3d..897c5bfdb82 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.SpecifiesTheWayToAlignTrailingComments.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.SpecifiesTheWayToAlignTrailingComments.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public SpecifiesTheWayToAlignTrailingComments Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.cs index e6ac9b2924f..c15589a6617 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.ClangFormat16AlignmentOptions.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public ClangFormat16AlignmentOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.cs index 246c6f33dd2..44673bae7c8 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlignTrailingCommentsEntity.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public AlignTrailingCommentsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortBlocksOnASingleLineEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortBlocksOnASingleLineEntity.cs index c652ec386e5..3e4e9c80114 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortBlocksOnASingleLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortBlocksOnASingleLineEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowShortBlocksOnASingleLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortFunctionsOnASingleLineEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortFunctionsOnASingleLineEntity.cs index 7ab8c03d0a7..79c242ca064 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortFunctionsOnASingleLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortFunctionsOnASingleLineEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowShortFunctionsOnASingleLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortIfStatementsOnASingleLineEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortIfStatementsOnASingleLineEntity.cs index b711fbf5794..7a9a5a0c7f0 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortIfStatementsOnASingleLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortIfStatementsOnASingleLineEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowShortIfStatementsOnASingleLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortLambdasOnASingleLineEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortLambdasOnASingleLineEntity.cs index 326400ed436..392a659cb0f 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortLambdasOnASingleLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AllowShortLambdasOnASingleLineEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowShortLambdasOnASingleLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterDefinitionReturnTypeEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterDefinitionReturnTypeEntity.cs index 61042cdf044..b3c074f07dd 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterDefinitionReturnTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterDefinitionReturnTypeEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AlwaysBreakAfterDefinitionReturnTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterReturnTypeEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterReturnTypeEntity.cs index a519e2d8c8c..c20c4614404 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterReturnTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakAfterReturnTypeEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AlwaysBreakAfterReturnTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakTemplateDeclarationsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakTemplateDeclarationsEntity.cs index 92e49295a27..3296b64bf42 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakTemplateDeclarationsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.AlwaysBreakTemplateDeclarationsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AlwaysBreakTemplateDeclarationsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BasedOnStyleEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BasedOnStyleEntity.cs index 063b2f9f444..e72a865f297 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BasedOnStyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BasedOnStyleEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BasedOnStyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BitFieldColonSpacingEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BitFieldColonSpacingEntity.cs index 716ccf2d25a..69fa305951c 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BitFieldColonSpacingEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BitFieldColonSpacingEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BitFieldColonSpacingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.Mutable.cs index ca380adb183..b05278533a7 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.Mutable.cs @@ -1400,6 +1400,31 @@ public bool RemoveSplitEmptyRecord() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.WrapControlStatementsIfForWhileSwitch.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.WrapControlStatementsIfForWhileSwitch.cs index ff9a1e3f19e..8b14e5cc158 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.WrapControlStatementsIfForWhileSwitch.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.WrapControlStatementsIfForWhileSwitch.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public WrapControlStatementsIfForWhileSwitch Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.cs index aca9de90890..766ba85d296 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BraceWrappingEntity.cs @@ -722,6 +722,12 @@ private void CheckValidInstance() public BraceWrappingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakAfterAttributesEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakAfterAttributesEntity.cs index 128fb2c0261..5eee7635e95 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakAfterAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakAfterAttributesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BreakAfterAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.ClangFormat12TheConceptDeclarationStyleToUse.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.ClangFormat12TheConceptDeclarationStyleToUse.cs index 1b523eac60d..593f758245d 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.ClangFormat12TheConceptDeclarationStyleToUse.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.ClangFormat12TheConceptDeclarationStyleToUse.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ClangFormat12TheConceptDeclarationStyleToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.cs index 1df3bcb112f..9af51abe789 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.BreakBeforeConceptDeclarationsEntity.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public BreakBeforeConceptDeclarationsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat14ThePenaltyForBreakingAfter.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat14ThePenaltyForBreakingAfter.cs index 7a4754f68d8..7877f93f528 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat14ThePenaltyForBreakingAfter.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat14ThePenaltyForBreakingAfter.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ClangFormat14ThePenaltyForBreakingAfter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat15ThePositionOfTheRequiresClause.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat15ThePositionOfTheRequiresClause.cs index fcf418b64b0..781af03876b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat15ThePositionOfTheRequiresClause.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat15ThePositionOfTheRequiresClause.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat15ThePositionOfTheRequiresClause Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16LineEndingStyleNOrRNToUse.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16LineEndingStyleNOrRNToUse.cs index 56a965996ad..bad2cb2dc5a 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16LineEndingStyleNOrRNToUse.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16LineEndingStyleNOrRNToUse.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat16LineEndingStyleNOrRNToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16TheInlineAsmColonStyleToUse.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16TheInlineAsmColonStyleToUse.cs index 1b30e3dbc50..0f052f2ad08 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16TheInlineAsmColonStyleToUse.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat16TheInlineAsmColonStyleToUse.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat16TheInlineAsmColonStyleToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat35LanguageThisFormatStyleIsTargetedAt.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat35LanguageThisFormatStyleIsTargetedAt.cs index 1740acd1c45..da5c86b2a88 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat35LanguageThisFormatStyleIsTargetedAt.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat35LanguageThisFormatStyleIsTargetedAt.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat35LanguageThisFormatStyleIsTargetedAt Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat36TheWayToWrapBinaryOperators.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat36TheWayToWrapBinaryOperators.cs index e2dd9eb73ab..e31a461e07b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat36TheWayToWrapBinaryOperators.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat36TheWayToWrapBinaryOperators.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat36TheWayToWrapBinaryOperators Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37IndentWidthForLineContinuations.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37IndentWidthForLineContinuations.cs index f92f7289847..b3adfa7030c 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37IndentWidthForLineContinuations.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37IndentWidthForLineContinuations.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ClangFormat37IndentWidthForLineContinuations Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37PointerAndReferenceAlignmentStyle.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37PointerAndReferenceAlignmentStyle.cs index aa59b5fbba1..66e5e334741 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37PointerAndReferenceAlignmentStyle.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37PointerAndReferenceAlignmentStyle.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat37PointerAndReferenceAlignmentStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheBraceBreakingStyleToUse.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheBraceBreakingStyleToUse.cs index 18cdc9bc9ff..1514ceb9780 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheBraceBreakingStyleToUse.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheBraceBreakingStyleToUse.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat37TheBraceBreakingStyleToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheColumnLimit.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheColumnLimit.cs index afc87e86018..8286ba8f48a 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheColumnLimit.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheColumnLimit.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ClangFormat37TheColumnLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheNumberOfColumnsUsedForTabStops.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheNumberOfColumnsUsedForTabStops.cs index 65add6b24c1..7b5810b9863 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheNumberOfColumnsUsedForTabStops.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat37TheNumberOfColumnsUsedForTabStops.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ClangFormat37TheNumberOfColumnsUsedForTabStops Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat5TheConstructorInitializersStyleToUse.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat5TheConstructorInitializersStyleToUse.cs index a48008dee31..a4a74b2d47f 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat5TheConstructorInitializersStyleToUse.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat5TheConstructorInitializersStyleToUse.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat5TheConstructorInitializersStyleToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat7TheInheritanceListStyleToUse.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat7TheInheritanceListStyleToUse.cs index 9a946c8b517..0ae224e6c26 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat7TheInheritanceListStyleToUse.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClangFormat7TheInheritanceListStyleToUse.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClangFormat7TheInheritanceListStyleToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClnagFormat37TheIndentationUsedForNamespaces.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClnagFormat37TheIndentationUsedForNamespaces.cs index 63a9ae5a942..069b0f1f246 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClnagFormat37TheIndentationUsedForNamespaces.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ClnagFormat37TheIndentationUsedForNamespaces.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ClnagFormat37TheIndentationUsedForNamespaces Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ConstructorInitializerIndentWidthEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ConstructorInitializerIndentWidthEntity.cs index 195b7c223e1..f7bf07f29b2 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ConstructorInitializerIndentWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ConstructorInitializerIndentWidthEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ConstructorInitializerIndentWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineAfterAccessModifierEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineAfterAccessModifierEntity.cs index cc4a6de9e71..4dd0a279d5c 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineAfterAccessModifierEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineAfterAccessModifierEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EmptyLineAfterAccessModifierEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineBeforeAccessModifierEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineBeforeAccessModifierEntity.cs index 955b52ee916..93f16e1f1d3 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineBeforeAccessModifierEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.EmptyLineBeforeAccessModifierEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EmptyLineBeforeAccessModifierEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ForEachMacArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ForEachMacArray.cs index c1a9f103e30..e52132904ec 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ForEachMacArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ForEachMacArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct ForEachMacArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ForEachMacArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IfMacrosJsArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IfMacrosJsArray.cs index 27abc45f812..e3b25c5f4c0 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IfMacrosJsArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IfMacrosJsArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct IfMacrosJsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public IfMacrosJsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IncludeBlocksEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IncludeBlocksEntity.cs index 5a094593ee8..ae55110060d 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IncludeBlocksEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IncludeBlocksEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IncludeBlocksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentExternBlockEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentExternBlockEntity.cs index 50ec41190ef..0900277b6d8 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentExternBlockEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentExternBlockEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IndentExternBlockEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentPpDirectivesEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentPpDirectivesEntity.cs index 3a16724fa2d..2362fef8d4d 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentPpDirectivesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentPpDirectivesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IndentPpDirectivesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentWidthEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentWidthEntity.cs index 107ff896ea4..5260d478f4a 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IndentWidthEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public IndentWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.InsertTrailingCommasEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.InsertTrailingCommasEntity.cs index 42612d48833..9b6253f1195 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.InsertTrailingCommasEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.InsertTrailingCommasEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public InsertTrailingCommasEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.Mutable.cs index ccf1627abae..c7a9a629845 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.Mutable.cs @@ -608,6 +608,31 @@ public bool RemoveHexMinDigits() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.cs index 2c1da549efb..f9312236643 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.IntegerLiteralSeparatorEntity.cs @@ -470,6 +470,12 @@ private void CheckValidInstance() public IntegerLiteralSeparatorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JavaScriptQuotesEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JavaScriptQuotesEntity.cs index f0db94597a9..286d9905ab4 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JavaScriptQuotesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JavaScriptQuotesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public JavaScriptQuotesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JsonStringArray.cs index 6f11a509757..e533a49db09 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.JsonStringArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.LambdaBodyIndentationEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.LambdaBodyIndentationEntity.cs index c335ef46143..e69ca7266ad 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.LambdaBodyIndentationEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.LambdaBodyIndentationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public LambdaBodyIndentationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.MaxEmptyLinesToKeepEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.MaxEmptyLinesToKeepEntity.cs index 2bdde3e4922..8dcb0c720ad 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.MaxEmptyLinesToKeepEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.MaxEmptyLinesToKeepEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public MaxEmptyLinesToKeepEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.Mutable.cs index 63d02cd2714..5dbe77d29ec 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.Mutable.cs @@ -10974,6 +10974,75 @@ public bool RemoveWhitespaceSensitiveMacros() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxEmptyLinesToKeepUtf8, out IJsonDocument? _, out int _)) + { + SetMaxEmptyLinesToKeep(Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.MaxEmptyLinesToKeepEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ObjCBinPackProtocolListUtf8, out IJsonDocument? _, out int _)) + { + SetObjCBinPackProtocolList(Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.ObjCBinPackProtocolListEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PpIndentWidthUtf8, out IJsonDocument? _, out int _)) + { + SetPpIndentWidth(Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.PpIndentWidthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShortNamespaceLinesUtf8, out IJsonDocument? _, out int _)) + { + SetShortNamespaceLines(Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.ShortNamespaceLinesEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BraceWrappingUtf8, out Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.BraceWrappingEntity.Mutable __corvusBraceWrapping)) + { + __corvusBraceWrapping.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IntegerLiteralSeparatorUtf8, out Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.IntegerLiteralSeparatorEntity.Mutable __corvusIntegerLiteralSeparator)) + { + __corvusIntegerLiteralSeparator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBeforeParensOptionsUtf8, out Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.SpaceBeforeParensOptionsEntity.Mutable __corvusSpaceBeforeParensOptions)) + { + __corvusSpaceBeforeParensOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpacesInLineCommentPrefixUtf8, out Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.SpacesInLineCommentPrefixEntity.Mutable __corvusSpacesInLineCommentPrefix)) + { + __corvusSpacesInLineCommentPrefix.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.NamespaceMArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.NamespaceMArray.cs index a7dd0624eb3..bba1a43a0d8 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.NamespaceMArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.NamespaceMArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct NamespaceMArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public NamespaceMArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBinPackProtocolListEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBinPackProtocolListEntity.cs index a58f08c77c4..40adec62280 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBinPackProtocolListEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBinPackProtocolListEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public ObjCBinPackProtocolListEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBlockIndentWidthEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBlockIndentWidthEntity.cs index 626b078c20a..2f157c5f443 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBlockIndentWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ObjCBlockIndentWidthEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ObjCBlockIndentWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PackConstructorInitializersEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PackConstructorInitializersEntity.cs index f73b8e91073..eb3f6bcbc40 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PackConstructorInitializersEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PackConstructorInitializersEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public PackConstructorInitializersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakAssignmentEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakAssignmentEntity.cs index 5e51d52ad0c..dfb42a4f48e 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakAssignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakAssignmentEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyBreakAssignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakBeforeFirstCallParameterEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakBeforeFirstCallParameterEntity.cs index e1d8ae65829..ffb605d2e91 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakBeforeFirstCallParameterEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakBeforeFirstCallParameterEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyBreakBeforeFirstCallParameterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakCommentEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakCommentEntity.cs index 1cbb4784990..9f5e0910ef4 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakCommentEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakCommentEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyBreakCommentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakFirstLessLessEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakFirstLessLessEntity.cs index ade882e2234..da539aa10ea 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakFirstLessLessEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakFirstLessLessEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyBreakFirstLessLessEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakStringEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakStringEntity.cs index bcffefc2f01..d3d931d4a7a 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakStringEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakStringEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyBreakStringEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakTemplateDeclarationEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakTemplateDeclarationEntity.cs index 7e4b36ab22c..e32b4fc3a1c 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakTemplateDeclarationEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyBreakTemplateDeclarationEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyBreakTemplateDeclarationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyExcessCharacterEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyExcessCharacterEntity.cs index b887685bffe..4809f1376fc 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyExcessCharacterEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyExcessCharacterEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyExcessCharacterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyIndentedWhitespaceEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyIndentedWhitespaceEntity.cs index b914da86cac..4b7afd7f1c6 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyIndentedWhitespaceEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyIndentedWhitespaceEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyIndentedWhitespaceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyReturnTypeOnItsOwnLineEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyReturnTypeOnItsOwnLineEntity.cs index eb075bb44e3..5d0f33e28cf 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyReturnTypeOnItsOwnLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PenaltyReturnTypeOnItsOwnLineEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public PenaltyReturnTypeOnItsOwnLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PpIndentWidthEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PpIndentWidthEntity.cs index 7fb4f2aecc2..09d686eaa4b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PpIndentWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.PpIndentWidthEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public PpIndentWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierAlignmentEntity.cs index 5bf39a40e43..d4539b74526 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierAlignmentEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public QualifierAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderArrayQualifierOrderEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderArrayQualifierOrderEntity.cs index ef546ddda82..e2a9f0b9018 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderArrayQualifierOrderEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderArrayQualifierOrderEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public QualifierOrderArrayQualifierOrderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderEntity.cs index ace57f14a73..91cabf78c77 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.QualifierOrderEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public QualifierOrderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.cs index f88a1d8a61d..653c5b8ea01 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.QualifierOrderArrayQualifierOrderEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct QualifierOrderArrayQualifierOrderEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public QualifierOrderArrayQualifierOrderEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.EnclosingFArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.EnclosingFArray.cs index 49e1c367094..057f8014657 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.EnclosingFArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.EnclosingFArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RawStringFormatsEntity public readonly partial struct EnclosingFArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public EnclosingFArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.JsonStringArray.cs index 68d07ddaab9..70998ee12e8 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.JsonStringArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RawStringFormatsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.Mutable.cs index 43212d1ceb6..b4ea79f8de7 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.Mutable.cs @@ -601,6 +601,31 @@ public bool RemoveLanguage() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.cs index f739d8d9494..3aee8a9d68d 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.RawStringFormatsEntity.cs @@ -431,6 +431,12 @@ private void CheckValidInstance() public RawStringFormatsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.cs index f5d14afb1bb..28793dee4a0 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RawStringFormatsEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct RawStringFormatsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RawStringFormatsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ReferenceAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ReferenceAlignmentEntity.cs index 777d4a150f6..ce071ce44a9 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ReferenceAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ReferenceAlignmentEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ReferenceAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.Mutable.cs index b4ef6829649..3e04a4435c8 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.Mutable.cs @@ -440,6 +440,31 @@ public bool RemoveSortPriority() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.PriorityEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.PriorityEntity.cs index f81272492af..cb5b360903b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.PriorityEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.PriorityEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public PriorityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.SortPriorityEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.SortPriorityEntity.cs index f640f6b1668..1b66854d18d 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.SortPriorityEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.SortPriorityEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public SortPriorityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.cs index b7b7cbe25cd..7fd113ad2df 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.RequiredPriorityAndRegex.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public RequiredPriorityAndRegex Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.cs index ea5fd7fc92c..808edb01966 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiredPriorityAndRegexArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct RequiredPriorityAndRegexArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RequiredPriorityAndRegexArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiresExpressionIndentationEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiresExpressionIndentationEntity.cs index 5320b02f40c..648a02f533f 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiresExpressionIndentationEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.RequiresExpressionIndentationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public RequiresExpressionIndentationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SeparateDefinitionBlocksEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SeparateDefinitionBlocksEntity.cs index a14781bcbd3..cadf1fd5cb5 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SeparateDefinitionBlocksEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SeparateDefinitionBlocksEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SeparateDefinitionBlocksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ShortNamespaceLinesEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ShortNamespaceLinesEntity.cs index 6fa045a5821..901fad01828 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ShortNamespaceLinesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.ShortNamespaceLinesEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public ShortNamespaceLinesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortIncludesEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortIncludesEntity.cs index c049ce70014..8786acd3d05 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortIncludesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortIncludesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SortIncludesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortJavaStaticImportEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortJavaStaticImportEntity.cs index 71295b44a70..13353a7c8a1 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortJavaStaticImportEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortJavaStaticImportEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SortJavaStaticImportEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.OneOf1Entity.cs index 0c017f8c743..6548daf22dd 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.OneOf1Entity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.cs index 6d63d78d091..a6b3ec74a01 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SortUsingDeclarationsEntity.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public SortUsingDeclarationsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceAroundPointerQualifiersEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceAroundPointerQualifiersEntity.cs index db52a25d62b..f035ed7460e 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceAroundPointerQualifiersEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceAroundPointerQualifiersEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SpaceAroundPointerQualifiersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensEntity.cs index 41e79a05ac4..8137bd36edd 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SpaceBeforeParensEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.Mutable.cs index 96c09e6c356..540259542a7 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.Mutable.cs @@ -806,6 +806,31 @@ public bool RemoveBeforeNonEmptyParentheses() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.cs index 0225beefdd5..5a1c78e071b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpaceBeforeParensOptionsEntity.cs @@ -533,6 +533,12 @@ private void CheckValidInstance() public SpaceBeforeParensOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesBeforeTrailingCommentsEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesBeforeTrailingCommentsEntity.cs index ded19f51eca..779db199a3b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesBeforeTrailingCommentsEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesBeforeTrailingCommentsEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public SpacesBeforeTrailingCommentsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInAnglesEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInAnglesEntity.cs index 9f07d38baa1..271516bad35 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInAnglesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInAnglesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SpacesInAnglesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MaximumEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MaximumEntity.cs index f70f2b6d8d4..897c44a658e 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MaximumEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MaximumEntity.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public MaximumEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MinimumEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MinimumEntity.cs index 5f86728c945..56f1e3f9df1 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MinimumEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.MinimumEntity.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public MinimumEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.Mutable.cs index d88847146ed..cce983fd066 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.Mutable.cs @@ -334,6 +334,41 @@ public bool RemoveMinimum() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaximumUtf8, out IJsonDocument? _, out int _)) + { + SetMaximum(Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.SpacesInLineCommentPrefixEntity.MaximumEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinimumUtf8, out IJsonDocument? _, out int _)) + { + SetMinimum(Corvus.ClangFormatBenchmark.Current.ClangFormatSchema.SpacesInLineCommentPrefixEntity.MinimumEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.cs index 3e900a3ac69..70a23705458 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.SpacesInLineCommentPrefixEntity.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public SpacesInLineCommentPrefixEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StandardEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StandardEntity.cs index 54f0d7beac7..c7c14c1e29f 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StandardEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StandardEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public StandardEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementAArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementAArray.cs index 7844c746409..b0bac8d92f1 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementAArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementAArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct StatementAArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public StatementAArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementMArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementMArray.cs index 134a1d85bd6..d762c890832 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementMArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.StatementMArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct StatementMArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public StatementMArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.TypenameMaArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.TypenameMaArray.cs index dc4a80266e0..1fa36b26956 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.TypenameMaArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.TypenameMaArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct TypenameMaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TypenameMaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.UseTabEntity.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.UseTabEntity.cs index 5d09f182684..bb136cda60a 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.UseTabEntity.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.UseTabEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public UseTabEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.WhitespaceArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.WhitespaceArray.cs index 947ad389432..7601550d107 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.WhitespaceArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.WhitespaceArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ClangFormatSchema public readonly partial struct WhitespaceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public WhitespaceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.cs index d8b26a321be..d9d5ab7ecf3 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/ClangFormatSchema.cs @@ -3608,6 +3608,12 @@ private void CheckValidInstance() public ClangFormatSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonArray.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonArray.cs index 47216d24bf6..f2463380dcc 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonArray.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonArray.cs @@ -23,11 +23,13 @@ namespace Corvus.ClangFormatBenchmark.Current; public readonly partial struct JsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public JsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonBoolean.cs index 2285053243d..039e238ee7e 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonInteger.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonInteger.cs index 1bcd88078f6..fe7e887b5d2 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonInteger.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonInteger.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonString.cs index 832cfd498c0..c5c5444ef3b 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/JsonString.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/corvusjson-jsonschema.lock index 485c8b303db..36a4ddd7dfd 100644 --- a/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.ClangFormatBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:16.3321114\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:45.0776951\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/HeightRangeDouble.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/HeightRangeDouble.cs index 6ae61727b79..1248bf2fafd 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/HeightRangeDouble.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/HeightRangeDouble.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public HeightRangeDouble Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonArray.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonArray.cs index 31e3d5b686f..b5d939f44d8 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonArray.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonArray.cs @@ -18,11 +18,13 @@ namespace Corvus.ClassicBenchmark.Current; public readonly partial struct JsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public JsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDate.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDate.cs index 55d3f98951c..8b7d5457269 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDate.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDate.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JsonDate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDecimal.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDecimal.cs index d1b35b09bf1..35720e5d4e9 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDecimal.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonDecimal.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonDecimal Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonEmail.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonEmail.cs index 7d3155d2c88..861a29a2a39 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonEmail.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/JsonEmail.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonEmail Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/OtherNames.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/OtherNames.cs index a49e78fb4f7..a54e40f1fcb 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/OtherNames.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/OtherNames.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public OtherNames Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.Mutable.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.Mutable.cs index 5859b473c4c..b6fbe13d46a 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.Mutable.cs @@ -542,6 +542,37 @@ public bool RemoveNetWorth() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NameUtf8, out Corvus.ClassicBenchmark.Current.PersonName.Mutable __corvusName)) + { + __corvusName.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.cs index 519815823f9..a591f9c562e 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/Person.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public Person Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonArray.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonArray.cs index 86c816e4f42..73481352218 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonArray.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonArray.cs @@ -18,11 +18,13 @@ namespace Corvus.ClassicBenchmark.Current; public readonly partial struct PersonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public PersonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.Mutable.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.Mutable.cs index 8a664c18888..bde9e371f67 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.Mutable.cs @@ -432,6 +432,31 @@ public bool RemoveOtherNames() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.cs index f379068b494..77c0196a584 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonName.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public PersonName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElement.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElement.cs index 0f1fe3d57b5..2cd28a14d3e 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElement.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElement.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public PersonNameElement Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElementArray.cs b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElementArray.cs index 1f84842fca1..0ab54b66535 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElementArray.cs +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/PersonNameElementArray.cs @@ -18,11 +18,13 @@ namespace Corvus.ClassicBenchmark.Current; public readonly partial struct PersonNameElementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public PersonNameElementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/corvusjson-jsonschema.lock index 4e917d12f84..7831fb44705 100644 --- a/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.ClassicBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:17.2114617\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:46.6581544\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs index 084cbe387ba..443d655c2d9 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ConfigurePresetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs index b73467832e8..9cba06e330c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs index 263f296c132..8415ff41964 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.cs index 4faee7f36b9..81828a8dddc 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.EnvironmentEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public EnvironmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs index 38f3c6854dd..70e6609db87 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs index a769936af16..1f60a91f644 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Type1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs index 265edf1b027..ef88013a501 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct InheritsEntity public readonly partial struct Type1EntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public Type1EntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.cs index db175cd6fc8..6804d46d6df 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.InheritsEntity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public InheritsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.JsonStringArray.cs index ba9983b55f0..523ed13bce9 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredName public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.Mutable.cs index 730ebfaa93b..551bb9f3f8e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.Mutable.cs @@ -1363,6 +1363,31 @@ public bool RemoveVerbose() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.NameEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.NameEntity.cs index d8e48ff8c17..ded3279ee60 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.NameEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.JsonStringArray.cs index 1221df3900d..3db0e218e84 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.JsonStringArray.cs @@ -32,11 +32,13 @@ public readonly partial struct TargetsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.cs index a9e93f8ace8..9839c691bfa 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.TargetsEntity.cs @@ -368,6 +368,12 @@ private void CheckValidInstance() public TargetsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.VendorEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.VendorEntity.cs index e369cb7d3d6..a9c2e93d1f6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.VendorEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.VendorEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public VendorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.cs index 4f5ef507a95..a6fdbeb145a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.RequiredName.cs @@ -649,6 +649,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.cs index 3aa20744962..86145585bbd 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV2.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct BuildPresetsItemsV2 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public BuildPresetsItemsV2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.Mutable.cs index 588754736ae..f44eff1cd59 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.Mutable.cs @@ -311,6 +311,31 @@ public bool RemoveCondition() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.cs index 195ff2499cd..3e5f109c4ef 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.BuildPresetsItemsV3Entity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public BuildPresetsItemsV3Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.cs index a0f085a101a..745d7b9644d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV3.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct BuildPresetsItemsV3 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public BuildPresetsItemsV3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.Mutable.cs index c2ace4b0d40..20a5fa7694d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.Mutable.cs @@ -280,6 +280,31 @@ public bool RemoveResolvePackageReferences() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.ResolvePackageReferencesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.ResolvePackageReferencesEntity.cs index 4669399edc8..11ca8e6d1d0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.ResolvePackageReferencesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.ResolvePackageReferencesEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ResolvePackageReferencesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.cs index 47965f938e6..4cef11f0a5a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.BuildPresetsItemsV4Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public BuildPresetsItemsV4Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.cs index e868de02355..2708d2ce37f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsItemsV4.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct BuildPresetsItemsV4 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public BuildPresetsItemsV4 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.Mutable.cs index 7dfcbdc2128..2c9f10131cc 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.Mutable.cs @@ -1585,6 +1585,31 @@ public bool RemoveVerbose() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.cs index f9e6726b5ff..dc92009286b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.RequiredName.cs @@ -513,6 +513,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.cs index d56abbfbc02..3c670d67645 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV2.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct BuildPresetsV2 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public BuildPresetsV2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.Mutable.cs index 9b9245304bd..770a1c52431 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.Mutable.cs @@ -1682,6 +1682,31 @@ public bool RemoveVerbose() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.cs index 4546fef7ae8..2f80a69f3f9 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.RequiredName.cs @@ -529,6 +529,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.cs index 401ad9b4633..8cf64444079 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV3.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct BuildPresetsV3 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public BuildPresetsV3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.Mutable.cs index 9e94672b18c..e7b251c9c58 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.Mutable.cs @@ -1779,6 +1779,31 @@ public bool RemoveVerbose() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.cs index 6ab23a89f57..bcaec8ab0a4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.RequiredName.cs @@ -545,6 +545,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.cs index ee6a9fe4245..41590835b4b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.BuildPresetsV4.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct BuildPresetsV4 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -342,6 +359,12 @@ private void CheckValidInstance() public BuildPresetsV4 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.Mutable.cs index 5ea8107a948..f5e1a366be8 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.Mutable.cs @@ -337,6 +337,31 @@ public bool RemovePatch() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.cs index 841fdf2c459..9f0b650eb69 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.CmakeMinimumRequired.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public CmakeMinimumRequired Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 0fd8bf63a18..8d0cf196dd1 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ConditionArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ConditionArray.cs index 86a91c63313..b3600dfedf6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ConditionArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.ConditionArray.cs @@ -30,11 +30,13 @@ public readonly partial struct ConditionRequiredConditionsAndType public readonly partial struct ConditionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ConditionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.Mutable.cs index 03e33e5e9f8..a324eec4175 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.Mutable.cs @@ -285,6 +285,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.cs index 366fefea451..ad1b2aa3b0c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredConditionsAndType.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ConditionRequiredConditionsAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 001ef5155dd..8f6fdacf6b6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.Mutable.cs index 6d0cdb89183..9ba0cb20b56 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.Mutable.cs @@ -306,6 +306,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.cs index 442a36dd559..83fc242b367 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredLhsAndRhsAndType.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public ConditionRequiredLhsAndRhsAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 5ca86a43d5b..475077afd82 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.JsonStringArray.cs index 46617eac7b5..2b6aef1a2b0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct ConditionRequiredListAndStringEntityAndType public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.Mutable.cs index ea338d16186..e9b61ece4f0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.Mutable.cs @@ -340,6 +340,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.cs index 228d7b29c00..f70841f62e3 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredListAndStringEntityAndType.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public ConditionRequiredListAndStringEntityAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index b72d37fbbc9..6f800626406 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.Mutable.cs index 55cffc18123..c8569fa2805 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.Mutable.cs @@ -306,6 +306,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.cs index 974adfee2d6..80f4b824740 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.ConditionRequiredRegexAndStringEntityAndType.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public ConditionRequiredRegexAndStringEntityAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 1e8e1a49ae6..92f5b0a5e3b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.Mutable.cs index ec4e6393604..d71e9d31e0c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.Mutable.cs @@ -282,6 +282,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.cs index 4969c06b551..fe474b5d52f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionAndType.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RequiredConditionAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index f01df5ee1c7..ef3886053bb 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ConditionArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ConditionArray.cs index 6fc1e351161..777d8255f98 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ConditionArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.ConditionArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredConditionsAndType public readonly partial struct ConditionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ConditionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.Mutable.cs index a74dda1d87a..a7934b69022 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.Mutable.cs @@ -285,6 +285,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.cs index 2ecdb139060..1687cd0b8ac 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredConditionsAndType.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RequiredConditionsAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 12207c32650..09e0931021b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.Mutable.cs index bfd7a9d6e8d..ca1bfca088b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.Mutable.cs @@ -306,6 +306,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.cs index bd1b9c6b703..da82abe6f8c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredLhsAndRhsAndType.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public RequiredLhsAndRhsAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 47812052965..c2247aabee0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.JsonStringArray.cs index 57712ff0777..c6028e844a7 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredListAndStringEntityAndType public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.Mutable.cs index ac98badb8d7..0ede322dc22 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.Mutable.cs @@ -340,6 +340,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.cs index 30d4d20d777..c4d3a2677b0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredListAndStringEntityAndType.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public RequiredListAndStringEntityAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 5a3c71c928a..1f9df95c633 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.Mutable.cs index ca9dfa6bb9e..4d40136cf7e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.Mutable.cs @@ -306,6 +306,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.cs index b96ace2454a..f4a3c202e70 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredRegexAndStringEntityAndType.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public RequiredRegexAndStringEntityAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.ARequiredStringSpecifyingTheTypeOfTheCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.ARequiredStringSpecifyingTheTypeOfTheCondition.cs index 5b8a9582d6c..1ba80e6a30a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.ARequiredStringSpecifyingTheTypeOfTheCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.ARequiredStringSpecifyingTheTypeOfTheCondition.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public ARequiredStringSpecifyingTheTypeOfTheCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.Mutable.cs index f058cb04cbe..da24701de25 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.Mutable.cs @@ -251,6 +251,31 @@ public void SetValue(scoped in Corvus.CmakePresetsBenchmark.Current.JsonBoolean. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.cs index 6b501f9bc2b..9e22e34d9c4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.RequiredTypeAndValue.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.cs index 65229968f71..8e4f93d5075 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Condition.cs @@ -651,6 +651,12 @@ private void CheckValidInstance() public Condition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetO_._CacheVariablesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetO_._CacheVariablesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.cs index 78184a7b0d2..20d8f3bf474 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetO_._CacheVariablesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetO_._CacheVariablesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnObjectRepresentingTheTypeAndValueOfTheVariable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.Mutable.cs index 59eb402efe9..5ab81a3ef9a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveTryCompile() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.cs index 3605bde11a6..15c8d4c8cd5 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingDebugOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.Mutable.cs index 8445944789e..a6ad22aae03 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveDev() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.cs index 86c2158028d..4bf22f69c5d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingErrors Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.Mutable.cs index fa340500178..42a73e55990 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.Mutable.cs @@ -473,6 +473,31 @@ public bool RemoveUnusedCli() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.cs index 05812e324b8..436afe7578e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.cs @@ -380,6 +380,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingWarnings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.Mutable.cs index 3256120b8be..e7a4664a482 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.StrategyEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.StrategyEntity.cs index 73f153dfde8..1645e50738e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.StrategyEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.StrategyEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public StrategyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.cs index 2bf1df37c02..94bd3e85a05 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.AnyOf1Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.cs index fddafb74ab5..78fa1d90169 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public ArchitectureEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.cs index b4dbb7bbb41..00744a6749c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.PropertyNamesEntity.cs index d1f1e2226b6..a5f898252c1 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.PropertyNamesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.cs index 2c0d4bca899..898ac4617f7 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public CacheVariablesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.AdditionalPropertiesEntity.cs index 34ce3b4d5d9..8b6a2fd7469 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.AdditionalPropertiesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.PropertyNamesEntity.cs index 35a81fd3f80..1dc028a1622 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.PropertyNamesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.cs index 5bbb163047c..66a40ff4d76 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.EnvironmentEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public EnvironmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.AnyOf0Entity.cs index 2209fe7ecf3..eb2fca31540 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.AnyOf0Entity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.Type1Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.Type1Entity.cs index 1c020c0ff64..bfda88960f2 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.Type1Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.Type1Entity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Type1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.cs index 323d2599ac4..f1e7a0c4102 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.Type1EntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct InheritsEntity public readonly partial struct Type1EntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public Type1EntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.cs index 98a45738eba..d1c1bfa646f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.InheritsEntity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public InheritsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.Mutable.cs index d52a755cb38..816a5dfee2b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.Mutable.cs @@ -1579,6 +1579,49 @@ public bool RemoveWarnings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.Mutable __corvusDebugValue)) + { + __corvusDebugValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ErrorsUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingErrors.Mutable __corvusErrors)) + { + __corvusErrors.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WarningsUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingWarnings.Mutable __corvusWarnings)) + { + __corvusWarnings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.NameEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.NameEntity.cs index 06da21ade41..5e564755f82 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.NameEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.Mutable.cs index ce2bdf26fc6..c3ea5f9fc87 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.StrategyEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.StrategyEntity.cs index bf8b4eda66f..fa6fdf191a4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.StrategyEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.StrategyEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public StrategyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.cs index 73897c24829..fc865cb8be9 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.AnyOf1Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.cs index 13323c7d49c..aff25c16a98 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ToolsetEntity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public ToolsetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.VendorEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.VendorEntity.cs index 33e517d0ff9..6b01b062b67 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.VendorEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.VendorEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public VendorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.cs index 8f37574ada6..912f08dddf1 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.cs @@ -667,6 +667,12 @@ private void CheckValidInstance() public AConfigurePresetObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._ity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._ity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.cs index b812bc858b6..4ef0566c6fd 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._ity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._ity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._sEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._sEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.Mutable.cs index b4fd40aa690..6e66fa893ac 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._sEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._sEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.Mutable.cs @@ -265,6 +265,31 @@ public void SetValue(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresets _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.cs index 06f6e8828a9..9cc61f0fdc4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV1.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct ConfigurePresetsItemsV1 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ConfigurePresetsItemsV1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.Mutable.cs index 1e13dd28cf7..7a6044ea127 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.Mutable.cs @@ -575,6 +575,31 @@ public bool RemoveToolchainFile() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.cs index 78504d197a0..13363b15b8d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.AConfigurePresetObject.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public AConfigurePresetObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.cs index d3e0d048c8c..df1b92814b9 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV3.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct ConfigurePresetsItemsV3 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ConfigurePresetsItemsV3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConf_._AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConf_._AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.cs index 6b597360850..7d2c3c0cadd 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConf_._AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConf_._AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.cs @@ -34,11 +34,13 @@ public readonly partial struct SourceEntity public readonly partial struct AStringRepresentingThePathToOneSourceFileToBeTracedArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public AStringRepresentingThePathToOneSourceFileToBeTracedArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceMode.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceMode.cs index 7ca57aefbb6..e8b1ad099d0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceMode.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceMode.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public AnOptionalStringThatSpecifiesTheTraceMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.cs index 366aeec7429..f43c913c27f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public AnOptionalStringThatSpecifiesTheTraceOutputFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.Mutable.cs index 05179816b0a..a6806ed68e3 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.Mutable.cs @@ -438,6 +438,31 @@ public bool RemoveSourceValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AnyOf0Entity.cs index 9eb78d43e4a..95d17e28dfb 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AnyOf0Entity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.cs index e32f4aee821..037985ad82f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.SourceEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public SourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.cs index 0f605576d48..613dad350bb 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.cs @@ -354,6 +354,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingTraceOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.Mutable.cs index 870786b8d3f..13f7f353d7f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveTrace() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TraceUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.Mutable __corvusTrace)) + { + __corvusTrace.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.cs index 56992cc08c0..0391ab99701 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public AConfigurePresetObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.cs index c6999348813..26efa3b04f5 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct ConfigurePresetsItemsV7 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ConfigurePresetsItemsV7 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7_._ntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7_._ntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.cs index 56248512dbc..7f996853bd5 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7_._ntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsItemsV7_._ntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public AStringRepresentingThePathToOneSourceFileToBeTraced Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.Mutable.cs index b21b4007a27..35e92f868b1 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.Mutable.cs @@ -1682,6 +1682,31 @@ public bool RemoveWarnings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.cs index e9682ae0399..618a84e2493 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.RequiredName.cs @@ -529,6 +529,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.cs index d96acb78b5c..55021d02a15 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV1.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct ConfigurePresetsV1 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public ConfigurePresetsV1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.Mutable.cs index 294ac8b2ad1..94fa86a9829 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.Mutable.cs @@ -1973,6 +1973,31 @@ public bool RemoveWarnings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.cs index 4a9d81cafed..99557c35df4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.RequiredName.cs @@ -577,6 +577,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.cs index 4ac4f50f6b3..a20a19f2c7e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV3.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct ConfigurePresetsV3 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public ConfigurePresetsV3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.Mutable.cs index b596fb07628..6bb529b5123 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.Mutable.cs @@ -2070,6 +2070,31 @@ public bool RemoveWarnings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.cs index cb1fc906a16..d47e85d66b2 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.RequiredName.cs @@ -593,6 +593,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.cs index c0a25eaa484..5eb3a7ecfdd 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.ConfigurePresetsV7.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct ConfigurePresetsV7 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -342,6 +359,12 @@ private void CheckValidInstance() public ConfigurePresetsV7 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Include.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Include.cs index e6a1bfd61ce..0100c55eec5 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Include.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Include.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct Include #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public Include Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Mutable.cs index 0d2374bdec3..e210edba0bf 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Mutable.cs @@ -439,6 +439,31 @@ public void SetVersion(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs index 6b588634847..228510b0b82 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveVerbose() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs index db97d731f11..68e18c66302 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingOutputOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.ConfigurePresetEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.ConfigurePresetEntity.cs index 1ad28c81285..91bd3ea7c1c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.ConfigurePresetEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.ConfigurePresetEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ConfigurePresetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs index 37ec30edfd2..d9320a904ed 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs index 7be17ab0869..7bf53db261a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.cs index 24839b91c73..8a8ae72b45a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.EnvironmentEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public EnvironmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.GeneratorsArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.GeneratorsArray.cs index 1db8c712228..3e94b705d66 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.GeneratorsArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.GeneratorsArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredName public readonly partial struct GeneratorsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public GeneratorsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.AnyOf0Entity.cs index 19e784a4533..0a7a598e381 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.AnyOf0Entity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs index 04571e234f3..1a613447134 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Type1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.cs index 32c40b43188..9be63792dab 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.Type1EntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct InheritsEntity public readonly partial struct Type1EntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public Type1EntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.cs index ef57be333ce..eecffef317b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.InheritsEntity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public InheritsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.JsonStringArray.cs index d9afb4652ca..7847534c617 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredName public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.Mutable.cs index b6d4c416f60..717b5393a45 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.Mutable.cs @@ -1735,6 +1735,37 @@ public bool RemoveVendorName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.NameEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.NameEntity.cs index 515362a5b90..cd87aa3f4f2 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.NameEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VariablesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VariablesEntity.cs index 14a41aaecc0..365293b9e3c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VariablesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VariablesEntity.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public VariablesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VendorEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VendorEntity.cs index dd824bb5de4..bf803ab5637 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VendorEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.VendorEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public VendorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.cs index 69610bc4a4d..cf6e9bb22ad 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.RequiredName.cs @@ -733,6 +733,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.cs index 71c7dc8c31c..09b250196fe 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsItemsV6.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct PackagePresetsItemsV6 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public PackagePresetsItemsV6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.Mutable.cs index ab9b8509c72..add100befbf 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.Mutable.cs @@ -1973,6 +1973,31 @@ public bool RemoveVendorName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.cs index 84a224f1dd0..a0e4f68442b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.RequiredName.cs @@ -577,6 +577,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.cs index 47014557867..1ea126812d5 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.PackagePresetsV6.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct PackagePresetsV6 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public PackagePresetsV6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.Require_._AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.Require_._AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.cs index 299681d03d4..f8da723f1dc 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.Require_._AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.Require_._AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.cs @@ -342,6 +342,12 @@ private void CheckValidInstance() public FixturesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredN_._AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredN_._AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.cs index 9001932679a..dd1b594b220 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredN_._AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredN_._AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingTestsToIncludeByTestIndex Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.Mutable.cs index 36701b5cc48..fe8483b78f8 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.Mutable.cs @@ -452,6 +452,37 @@ public bool RemoveName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FixturesUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.Mutable __corvusFixtures)) + { + __corvusFixtures.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.cs index fe54f5d2b30..e4c64d69bc5 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingWhichTestsToExclude Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.cs index 360d47aa28b..d9af0dfd432 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public IndexEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.Mutable.cs index 141cc549f0c..ea3d7aecebf 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.Mutable.cs @@ -440,6 +440,31 @@ public bool RemoveUseUnion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.cs index 83efdef0c0b..e8d7c9bb77e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.cs @@ -356,6 +356,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingWhichTestsToInclude Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.Mutable.cs index 0667cea8173..cf435d59b68 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.Mutable.cs @@ -347,6 +347,43 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExcludeUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.Mutable __corvusExclude)) + { + __corvusExclude.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IncludeUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.Mutable __corvusInclude)) + { + __corvusInclude.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.cs index e8b473e5599..f3a5dae5d1a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingHowToFilterTheTestsToRun Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.Mutable.cs index cbc8402c4c6..828f10d715c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.Mutable.cs @@ -905,6 +905,37 @@ public bool RemoveTimeout() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RepeatUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.Mutable __corvusRepeat)) + { + __corvusRepeat.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.NoTestsActionEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.NoTestsActionEntity.cs index ad07f61c7a0..9e6805f5bca 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.NoTestsActionEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.NoTestsActionEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public NoTestsActionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.ModeEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.ModeEntity.cs index 75526f087a7..b18b3bd80b7 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.ModeEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.ModeEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public ModeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.Mutable.cs index cd6961d3a2f..7dd707d57d6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.Mutable.cs @@ -255,6 +255,31 @@ public void SetMode(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.cs index c0fc74270df..bf25742efdb 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.RequiredCountAndMode.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public RequiredCountAndMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.ShowOnlyEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.ShowOnlyEntity.cs index cf232347578..7e0fa1959a9 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.ShowOnlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.ShowOnlyEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public ShowOnlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.cs index cd2c41cd6f4..96ef07be061 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.cs @@ -506,6 +506,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingOptionsForTestExecution Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs index fc14eec8f76..bccff0e0381 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs @@ -942,6 +942,31 @@ public bool RemoveVerbosity() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.VerbosityEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.VerbosityEntity.cs index a6d569eff77..8daed62c410 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.VerbosityEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.VerbosityEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public VerbosityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs index ffb92270eba..ced8ed0b78d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.cs @@ -579,6 +579,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingOutputOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs index f34a58936f8..71b20b2d62e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.ConfigurePresetEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ConfigurePresetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs index 397a3be41ea..be77f0a02c8 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.AdditionalPropertiesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs index cb3f403969a..a2ddd8e8f0d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.PropertyNamesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.cs index 0b45a611aa1..5e84f44e4f8 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.EnvironmentEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public EnvironmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs index 51a0f244123..cddc59447fc 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.AnyOf0Entity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs index 0882e4d1790..f3a3f8d38bd 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.Type1Entity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Type1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs index 5e1356fad53..e6782025e74 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.Type1EntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct InheritsEntity public readonly partial struct Type1EntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public Type1EntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.cs index 15c19822bfc..0c96cd02faf 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.InheritsEntity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public InheritsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.JsonStringArray.cs index bab1707192a..eb319856956 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredName public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.Mutable.cs index 57b3af5c9b2..566bf79e27b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.Mutable.cs @@ -1374,6 +1374,49 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExecutionUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOptionsForTestExecution.Mutable __corvusExecution)) + { + __corvusExecution.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilterUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.Mutable __corvusFilter)) + { + __corvusFilter.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingOutputOptions.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.NameEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.NameEntity.cs index 43f71e18304..9dde2e066b4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.NameEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.VendorEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.VendorEntity.cs index 13df57ce51e..e21745a966f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.VendorEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.VendorEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public VendorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.cs index ab1de2cdd7d..4e74e1babca 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName.cs @@ -633,6 +633,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._bjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._bjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.Mutable.cs index 9595c7aee34..adad8d3a692 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._bjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._bjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.Mutable.cs @@ -449,6 +449,31 @@ public bool RemoveStride() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.Mutable.cs index 7e7b5acdb45..328a1ec7935 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.Mutable.cs @@ -345,6 +345,31 @@ public bool RemoveSetup() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.cs index 3903de1bac4..81a6e4c724a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.cs @@ -38,11 +38,13 @@ public readonly partial struct AnOptionalObjectSpecifyingTestsToIncludeByTestInd public readonly partial struct JsonIntegerArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -120,6 +122,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -333,6 +350,12 @@ private void CheckValidInstance() public JsonIntegerArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.cs index 9dd3b5b565b..c303f619f3f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV2.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsItemsV2 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TestPresetsItemsV2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.Mutable.cs index 17a0fc8845b..107ef4c804a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.Mutable.cs @@ -311,6 +311,31 @@ public bool RemoveCondition() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.cs index fb6add526f9..eddda888969 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.TestPresetsItemsV3Entity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public TestPresetsItemsV3Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.cs index efb9738f076..d5504a72d80 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV3.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsItemsV3 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TestPresetsItemsV3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs index dfb5f7a3069..b52b562db6b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs @@ -282,6 +282,31 @@ public bool RemoveTestOutputTruncation() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.TestOutputTruncationEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.TestOutputTruncationEntity.cs index 8f4515805a2..22844fb32b8 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.TestOutputTruncationEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.TestOutputTruncationEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TestOutputTruncationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.cs index 7b2d4fe7069..216aaea5576 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingOutputOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.Mutable.cs index 339ac7d306e..20a849d790c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveOutput() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.cs index 7fc383a2181..9136055f850 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.TestPresetsItemsV5Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public TestPresetsItemsV5Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.cs index 101144f240d..4d519306a71 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV5.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsItemsV5 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TestPresetsItemsV5 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs index 3bb1cd98aac..782446c3d70 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable.cs @@ -282,6 +282,31 @@ public bool RemoveOutputJUnitFile() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.cs index 3579b9c048f..7d985514ec7 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public AnOptionalObjectSpecifyingOutputOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.Mutable.cs index 463de307638..df14c30e4e7 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveOutput() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.AnOptionalObjectSpecifyingOutputOptions.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.cs index c1c1d08904a..cb735e839a0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.TestPresetsItemsV6Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public TestPresetsItemsV6Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.cs index 982a428968d..f13abcd024e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsItemsV6.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsItemsV6 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TestPresetsItemsV6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.Mutable.cs index 14232da0d90..30fcd4ed1e6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.Mutable.cs @@ -1488,6 +1488,37 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.Mutable.cs index da273aeac1e..0615b558d55 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.Mutable.cs @@ -1210,6 +1210,31 @@ public bool RemoveVerbosity() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.cs index 61189755ee7..f2bf155163e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.OutputEntity.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public OutputEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.cs index 6d8c25d8ea0..d68c9c95c4d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.RequiredName.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.cs index d74b989d92f..2a657e2b6bd 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV2.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsV2 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public TestPresetsV2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.Mutable.cs index 8b689d19d73..2d8c8d2415c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.Mutable.cs @@ -1585,6 +1585,37 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.Mutable.cs index 1459aa17fcc..8e663ddd539 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.Mutable.cs @@ -1210,6 +1210,31 @@ public bool RemoveVerbosity() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.cs index 2586fbad37c..35b5a89c29a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.OutputEntity.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public OutputEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.cs index d69d974b4a0..13e695112f9 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.RequiredName.cs @@ -513,6 +513,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.cs index f4fc958f059..790f5c997ed 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV3.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsV3 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public TestPresetsV3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.Mutable.cs index db29a9f3e5e..1f31680f355 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.Mutable.cs @@ -1585,6 +1585,37 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.Mutable.cs index 8b3aacbf9d3..55434136392 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.Mutable.cs @@ -1307,6 +1307,31 @@ public bool RemoveVerbosity() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.cs index 7a0548764ca..0254988007f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.OutputEntity.cs @@ -462,6 +462,12 @@ private void CheckValidInstance() public OutputEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.cs index d125445d39c..62cd698eeba 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.RequiredName.cs @@ -513,6 +513,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.cs index ef45b2c735a..6c389161b59 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV5.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsV5 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -342,6 +359,12 @@ private void CheckValidInstance() public TestPresetsV5 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.Mutable.cs index 953e4176df8..7a8ccc8b5e3 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.Mutable.cs @@ -1585,6 +1585,37 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.Mutable __corvusOutput)) + { + __corvusOutput.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.Mutable.cs index e00addd0115..c6826810a1e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.Mutable.cs @@ -1404,6 +1404,31 @@ public bool RemoveVerbosity() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.cs index 5c93b1b11b9..8caab77cdaf 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.OutputEntity.cs @@ -478,6 +478,12 @@ private void CheckValidInstance() public OutputEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.cs index 22465e54044..2e4007e713b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.RequiredName.cs @@ -513,6 +513,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.cs index ec4ccb6e5ed..a602b115c86 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TestPresetsV6.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct TestPresetsV6 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -360,6 +377,12 @@ private void CheckValidInstance() public TestPresetsV6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TopCondition.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TopCondition.cs index 72aa84ba3ec..be3f54c2cdd 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TopCondition.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.TopCondition.cs @@ -678,6 +678,12 @@ private void CheckValidInstance() public TopCondition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Vendor.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Vendor.cs index 01bd061499f..a5bb2d6ff1f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Vendor.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.Vendor.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public Vendor Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index dac7b91cce1..ec09c6251f0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.Mutable.cs index 8c902e24106..b6db1908d2b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.Mutable.cs @@ -511,6 +511,37 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.cs index 736a55aaee5..c6b08f0b921 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType1.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public WithVersionType1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index 6a85d28c0f6..92f574a3695 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.Mutable.cs index 8cf84e2e47c..c7f9d5c2424 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.Mutable.cs @@ -715,6 +715,37 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.cs index 0a9a9e27cb6..d7920a6432c 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType2.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public WithVersionType2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index 8692ca6b39f..84006a129f7 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.Mutable.cs index bdd10395bfb..482e376202b 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.Mutable.cs @@ -715,6 +715,37 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.cs index 19dddca1124..91cef06af70 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType3.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public WithVersionType3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index 0485e489340..dc9bbc9dc96 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.Mutable.cs index d5ac716b845..632a435d594 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.Mutable.cs @@ -817,6 +817,37 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.cs index 195c21957a5..18c2bf4e8bf 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType4.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public WithVersionType4 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index 663d4d50039..e853ef52283 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.Mutable.cs index 9aba703e6ea..e7de35968a0 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.Mutable.cs @@ -817,6 +817,37 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.cs index 92780ee9593..fd4fac6db93 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType5.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public WithVersionType5 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index 59ad6edc454..db79e314814 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.Mutable.cs index 05d15af08ba..d258acb6877 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.Mutable.cs @@ -1021,6 +1021,37 @@ public bool RemoveWorkflowPresets() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.cs index 1f8ebe76182..a175c56e805 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType6.cs @@ -455,6 +455,12 @@ private void CheckValidInstance() public WithVersionType6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index f6edf910df7..b4c58129818 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.Mutable.cs index b1e498a57c0..109e79420e3 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.Mutable.cs @@ -1021,6 +1021,37 @@ public bool RemoveWorkflowPresets() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.cs index f01e18e9845..d4ee7d4b42e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType7.cs @@ -455,6 +455,12 @@ private void CheckValidInstance() public WithVersionType7 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs index c6b21c071e3..22d248ded5f 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.ARequiredIntegerRepresentingTheVersionOfTheJsonSchema.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public ARequiredIntegerRepresentingTheVersionOfTheJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.Mutable.cs index 64489f68910..58e39241784 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.Mutable.cs @@ -1087,6 +1087,37 @@ public bool RemoveWorkflowPresets() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CmakeMinimumRequiredValueUtf8, out Corvus.CmakePresetsBenchmark.Current.CmakePresetsSchema.CmakeMinimumRequired.Mutable __corvusCmakeMinimumRequiredValue)) + { + __corvusCmakeMinimumRequiredValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.cs index 2bc0dc9592d..0c8304c2d94 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WithVersionType8.cs @@ -476,6 +476,12 @@ private void CheckValidInstance() public WithVersionType8 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.Mutable.cs index cdede4e1ed7..ca3e2d4fd46 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.Mutable.cs @@ -519,6 +519,31 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.NameEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.NameEntity.cs index 4155f70bf44..e42e5cee02a 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.NameEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.Mutable.cs index 088713b500b..18210805d99 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.Mutable.cs @@ -255,6 +255,31 @@ public void SetType(scoped in Corvus.CmakePresetsBenchmark.Current.CmakePresetsS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.NameEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.NameEntity.cs index bd3150fda9c..932cecbda2d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.NameEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.TypeEntity.cs index 75431e7a156..73c14453fab 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.TypeEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.cs index 97fd7c29052..4de7a7211d6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.RequiredNameAndType.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RequiredNameAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.cs index 12d20366489..e2c42958691 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.RequiredNameAndTypeArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredNameAndSteps public readonly partial struct RequiredNameAndTypeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RequiredNameAndTypeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.VendorEntity.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.VendorEntity.cs index 5ad5b360fb2..6a049377fd6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.VendorEntity.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.VendorEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public VendorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.cs index 60c0253121a..cb8418bb0df 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.RequiredNameAndSteps.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public RequiredNameAndSteps Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.cs index 90dd5f3657f..12400ca15bf 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsItemsV6.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct WorkflowPresetsItemsV6 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public WorkflowPresetsItemsV6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.Mutable.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.Mutable.cs index 33f15883b3a..db9f6a3e0b4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.Mutable.cs @@ -604,6 +604,31 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.cs index 59a9a1177ed..0ebba6ea532 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.RequiredNameAndSteps.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public RequiredNameAndSteps Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.cs index a9091bd30ff..69462ea11b7 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.WorkflowPresetsV6.cs @@ -26,11 +26,13 @@ public readonly partial struct CmakePresetsSchema public readonly partial struct WorkflowPresetsV6 #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public WorkflowPresetsV6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.cs index d54a4d1baf7..8d0df26fd4e 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/CmakePresetsSchema.cs @@ -578,6 +578,12 @@ private void CheckValidInstance() public CmakePresetsSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonBoolean.cs index 68b5c3e9436..e713ccfc14d 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonInteger.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonInteger.cs index 3978358d11a..9eb5c5332ef 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonInteger.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonInteger.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonNull.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonNull.cs index 0f380e4b9e0..f3df1fa2586 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonNull.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonNull.cs @@ -261,6 +261,12 @@ private void CheckValidInstance() public JsonNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonString.cs index ea33980982c..ff1a792b9d4 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonUriReference.cs b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonUriReference.cs index 06bbeb5bca1..f3b1abafe24 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonUriReference.cs +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/JsonUriReference.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public JsonUriReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/corvusjson-jsonschema.lock index 55ea0318cb0..0cd558356b6 100644 --- a/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.CmakePresetsBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:18.3519414\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:48.5749148\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { @@ -187,7 +187,6 @@ "CmakePresetsSchema.Condition.RequiredTypeAndValue.Mutable.cs", "CmakePresetsSchema.Condition.RequiredTypeAndValue.cs", "CmakePresetsSchema.Condition.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetO_._CacheVariablesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.AnOptionalObjectSpecifyingDebugOptions.cs", @@ -206,6 +205,7 @@ "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.ArchitectureEntity.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.CacheVariablesEntity.AdditionalPropertiesEntity.cs", @@ -254,11 +254,11 @@ "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.VendorEntity.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.VendorEntity.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._ity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._nalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.JsonSchema.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._sEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.Mutable.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._tionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.Mutable.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._tity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.JsonSchema.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.Mutable.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._ditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.JsonSchema.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._esEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.ValueEntity.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._iablesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.Mutable.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV1.AConfigurePresetObject_._lesEntity.AdditionalPropertiesEntity.AnObjectRepresentingTheTypeAndValueOfTheVariable.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV1.cs", @@ -268,12 +268,12 @@ "CmakePresetsSchema.ConfigurePresetsItemsV3.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV3.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV3.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7.AConf_._AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePres_._AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.JsonSchema.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetO_._AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.Mutable.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7.AC_._AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.Mutable.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObj_._AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceMode.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceMode.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceMode.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.AnOptionalStringThatSpecifiesTheTraceOutputFormat.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.AnOptionalObjectSpecifyingTraceOptions.Mutable.cs", @@ -287,14 +287,14 @@ "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject_._aceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.JsonSchema.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject_._gTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.Mutable.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject_._ifyingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.Mutable.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigurePresetObject_._ingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.JsonSchema.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7.AConfigure_._AnOptionalObjectSpecifyingTraceOptions.SourceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsItemsV7.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7_._ngRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.JsonSchema.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7_._ntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.cs", - "CmakePresetsSchema.ConfigurePresetsItemsV7_._tringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.Mutable.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7_._AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.JsonSchema.cs", + "CmakePresetsSchema.ConfigurePresetsItemsV7_._urceEntity.AStringRepresentingThePathToOneSourceFileToBeTracedArray.AStringRepresentingThePathToOneSourceFileToBeTraced.cs", "CmakePresetsSchema.ConfigurePresetsV1.JsonSchema.cs", "CmakePresetsSchema.ConfigurePresetsV1.Mutable.cs", "CmakePresetsSchema.ConfigurePresetsV1.RequiredName.JsonSchema.cs", @@ -374,10 +374,9 @@ "CmakePresetsSchema.PackagePresetsV6.cs", "CmakePresetsSchema.TestPresetsItemsV2.JsonSchema.cs", "CmakePresetsSchema.TestPresetsItemsV2.Mutable.cs", - "CmakePresetsSchema.TestPresetsItemsV2.Require_._AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredN_._AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObje_._IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.JsonSchema.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectS_._IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.Mutable.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpe_._IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.JsonSchema.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecif_._IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.Mutable.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.cs", "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.JsonSchema.cs", "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.Mutable.cs", "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.AnOptionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.cs", @@ -445,13 +444,14 @@ "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.VendorEntity.Mutable.cs", "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.VendorEntity.cs", "CmakePresetsSchema.TestPresetsItemsV2.RequiredName.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.Mutable.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._SpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.JsonSchema.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._bjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.Mutable.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ctSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonSchema.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.Mutable.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.JsonSchema.cs", - "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._alObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.Mutable.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._alObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.JsonSchema.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._bjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToExclude.FixturesEntity.JsonSchema.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._ionalObjectSpecifyingHowToFilterTheTestsToRun.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.Mutable.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._lObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonSchema.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._n.AnOptionalObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._onalObjectSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.Mutable.cs", + "CmakePresetsSchema.TestPresetsItemsV2.RequiredName_._tSpecifyingWhichTestsToInclude.IndexEntity.AnOptionalObjectSpecifyingTestsToIncludeByTestIndex.JsonIntegerArray.cs", "CmakePresetsSchema.TestPresetsItemsV2.cs", "CmakePresetsSchema.TestPresetsItemsV3.JsonSchema.cs", "CmakePresetsSchema.TestPresetsItemsV3.Mutable.cs", diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.Mutable.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.Mutable.cs index 7a2f3fe012c..32b6b754bd5 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.Mutable.cs @@ -1192,6 +1192,91 @@ public bool RemoveSimilarCode() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ArgumentCountUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusArgumentCount)) + { + __corvusArgumentCount.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComplexLogicUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusComplexLogic)) + { + __corvusComplexLogic.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FileLinesUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusFileLines)) + { + __corvusFileLines.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IdenticalCodeUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusIdenticalCode)) + { + __corvusIdenticalCode.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MethodComplexityUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusMethodComplexity)) + { + __corvusMethodComplexity.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MethodCountUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusMethodCount)) + { + __corvusMethodCount.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MethodLinesUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusMethodLines)) + { + __corvusMethodLines.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NestedControlFlowUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusNestedControlFlow)) + { + __corvusNestedControlFlow.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReturnStatementsUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusReturnStatements)) + { + __corvusReturnStatements.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SimilarCodeUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.Mutable __corvusSimilarCode)) + { + __corvusSimilarCode.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.cs index 8fdef530606..b0ad7c5797d 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Checks.cs @@ -509,6 +509,12 @@ private void CheckValidInstance() public Checks Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.EnabledEntity.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.EnabledEntity.cs index d770d659064..5239c58e78c 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.EnabledEntity.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.EnabledEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnabledEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.Mutable.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.Mutable.cs index cd926335c5f..31164f9987d 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.Mutable.cs @@ -274,6 +274,36 @@ public bool RemoveEnabledValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledValueUtf8, out IJsonDocument? _, out int _)) + { + SetEnabledValue(Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Enabled.EnabledEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.cs index b8e36f15ea6..51d91ef06b7 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Enabled.cs @@ -356,6 +356,12 @@ private void CheckValidInstance() public Enabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.JsonStringArray.cs index 719dfb73cd0..fc6924c154c 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct CodeClimateSchema public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Mutable.cs index 197a0977ebd..3e2a3dd902d 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Mutable.cs @@ -673,6 +673,42 @@ public bool RemoveVersionValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionValueUtf8, out IJsonDocument? _, out int _)) + { + SetVersionValue(Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Version.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ChecksValueUtf8, out Corvus.CodeClimateBenchmark.Current.CodeClimateSchema.Checks.Mutable __corvusChecksValue)) + { + __corvusChecksValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Plugins.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Plugins.cs index d34c0c08a6f..2dcb5e462bd 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Plugins.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Plugins.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public Plugins Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.Mutable.cs index 43825cfc7f2..6622adc637f 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.Mutable.cs @@ -338,6 +338,31 @@ public bool RemoveUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.cs index ec3f1530db4..fefa5acf2ac 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.PrepareEntity.cs @@ -375,6 +375,12 @@ private void CheckValidInstance() public PrepareEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.cs index c607f15d979..4392c142f83 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.PrepareEntityArray.cs @@ -21,11 +21,13 @@ public readonly partial struct CodeClimateSchema public readonly partial struct PrepareEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public PrepareEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Version.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Version.cs index 3202acb434d..caec8889eae 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Version.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.Version.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Version Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.cs index b698b6cda6b..d7198a1b800 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/CodeClimateSchema.cs @@ -436,6 +436,12 @@ private void CheckValidInstance() public CodeClimateSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonString.cs index fa1fc3cf949..a2619977ab1 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonUri.cs b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonUri.cs index 5e3e0d61773..15c2c6ebac0 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonUri.cs +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/JsonUri.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public JsonUri Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/corvusjson-jsonschema.lock index f31037dbaa6..989e5c1fe40 100644 --- a/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.CodeClimateBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:19.1929602\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:50.1537299\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.ArgsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.ArgsEntity.cs index a0f8224284e..5eea12c1f80 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.ArgsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.ArgsEntity.cs @@ -532,6 +532,12 @@ private void CheckValidInstance() public ArgsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.cs index c140764874a..dfcf0150034 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.ArgsEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Accenti public readonly partial struct ArgsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -92,6 +94,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -305,6 +322,12 @@ private void CheckValidInstance() public ArgsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.Mutable.cs index 8cc35bf8fe9..79a84a99ce9 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Accenti.OpEn _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.OpEntity.cs index 36501b71b42..2045afef7d1 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.cs index ad569800ca8..94d9d336fde 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Accenti.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public Accenti Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Cql2SchemaArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Cql2SchemaArray.cs index 21f8d89f5d5..c3876c2065e 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Cql2SchemaArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Cql2SchemaArray.cs @@ -23,11 +23,13 @@ public readonly partial struct AndOrExpression public readonly partial struct Cql2SchemaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public Cql2SchemaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Mutable.cs index 8b0005f7fb4..68f870fe121 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.AndOrExpress _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.OpEntity.cs index ca951ecb29b..8426b96b879 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.cs index 624564e9545..8074c443bdd 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.AndOrExpression.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public AndOrExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.Mutable.cs index ec71e2f2efc..d5c3535f604 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.ArithmeticEx _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.OpEntity.cs index 607d86e210c..dadcc6d0f70 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.cs index c30792b3660..1c0d3172099 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticExpression.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public ArithmeticExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.ArithmeticOperandsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.ArithmeticOperandsEntity.cs index ab730255918..84722d8bd49 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.ArithmeticOperandsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.ArithmeticOperandsEntity.cs @@ -560,6 +560,12 @@ private void CheckValidInstance() public ArithmeticOperandsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.cs index 1524dbbab00..d6f1d4698de 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArithmeticOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct ArithmeticOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public ArithmeticOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.ArrayExpressionEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.ArrayExpressionEntity.cs index 9092fb170e2..c2a10f0e7c3 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.ArrayExpressionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.ArrayExpressionEntity.cs @@ -1544,6 +1544,12 @@ private void CheckValidInstance() public ArrayExpressionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.cs index 27c1080ffce..9c0b5809fb2 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayExpression.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct ArrayExpression #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public ArrayExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.ArrayOperandsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.ArrayOperandsEntity.cs index b7403d12288..1bb0e9e2968 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.ArrayOperandsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.ArrayOperandsEntity.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public ArrayOperandsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.cs index 8b9907ab0dc..f699c297253 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct ArrayOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public ArrayOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.Mutable.cs index 0d34d1cafed..0c1a31fd549 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.ArrayPredica _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.OpEntity.cs index 4925196cf3c..89409f088ad 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.cs index 467d6279339..c92c0b6cd49 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ArrayPredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public ArrayPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf0Entity.cs index fdda730c380..222d663297f 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf0Entity.cs @@ -23,11 +23,13 @@ public readonly partial struct Bbox public readonly partial struct OneOf0Entity #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf1Entity.cs index 4f7de50ba6f..2121062b4b3 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.OneOf1Entity.cs @@ -23,11 +23,13 @@ public readonly partial struct Bbox public readonly partial struct OneOf1Entity #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.cs index 0abff0ce037..39875a1b512 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Bbox.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct Bbox #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -370,6 +387,12 @@ private void CheckValidInstance() public Bbox Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.Mutable.cs index 5af0ddce372..7f6aada84a8 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.Mutable.cs @@ -298,6 +298,31 @@ public void SetBboxValue(in Corvus.Cql2Benchmark.Current.Cql2Schema.Bb _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.cs index dea494951ae..b8b87f1ca8a 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BboxLiteral.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public BboxLiteral Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.Mutable.cs index 84ba00cf50e..8009376e374 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.BinaryCompar _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.OpEntity.cs index 17ef4861d38..c7484614a67 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.cs index e81d6c6d913..1a49f54b1fd 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.BinaryComparisonPredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public BinaryComparisonPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.ArgsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.ArgsEntity.cs index c93907ea3ad..4809ad40d15 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.ArgsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.ArgsEntity.cs @@ -532,6 +532,12 @@ private void CheckValidInstance() public ArgsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.cs index 0c66c33b84c..996ee3ce206 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.ArgsEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Casei public readonly partial struct ArgsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -92,6 +94,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -305,6 +322,12 @@ private void CheckValidInstance() public ArgsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.Mutable.cs index c53826af884..18320f84387 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Casei.OpEnti _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.OpEntity.cs index 8256b6ba560..a055d617736 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.cs index daf2c0c4f57..f1414c585f5 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Casei.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public Casei Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.CharacterExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.CharacterExpression.cs index e23d58eee67..5a5c80c8f2a 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.CharacterExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.CharacterExpression.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public CharacterExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ComparisonPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ComparisonPredicate.cs index 3f7fad845ff..7f8c4afaadc 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ComparisonPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ComparisonPredicate.cs @@ -474,6 +474,12 @@ private void CheckValidInstance() public ComparisonPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.Mutable.cs index 5d68a98b0b7..e30158cc852 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.Mutable.cs @@ -264,6 +264,31 @@ public void SetDate(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.DateString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.cs index 1dae13d5440..a561c7f502c 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateInstant.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public DateInstant Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateString.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateString.cs index 5c0d11190d3..6b13ded52fb 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateString.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.DateString.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public DateString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.ArgsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.ArgsEntity.cs index 855ed390a2e..e5ce047ceae 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.ArgsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.ArgsEntity.cs @@ -1546,6 +1546,12 @@ private void CheckValidInstance() public ArgsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.cs index 5c15cfefdbe..fa8f8e03c70 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.ArgsEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct FunctionRef public readonly partial struct ArgsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ArgsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.Mutable.cs index e7c1121ed75..5b0b086e1b9 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.FunctionRef. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.NotEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.NotEntity.cs index e57bbb241ea..451dc5c4a57 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.NotEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.NotEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public NotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.cs index 47f27aad31f..6fb0348ee32 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.cs index 6a6f88f87c1..32e12f36c1f 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.FunctionRef.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public FunctionRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.GeometryLiteral.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.GeometryLiteral.cs index 3feeab0d79f..33a402dc686 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.GeometryLiteral.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.GeometryLiteral.cs @@ -528,6 +528,12 @@ private void CheckValidInstance() public GeometryLiteral Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.GeometriesEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.GeometriesEntity.cs index ec32b1154dc..9076d1ba5f8 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.GeometriesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.GeometriesEntity.cs @@ -505,6 +505,12 @@ private void CheckValidInstance() public GeometriesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.cs index 86d7df81be9..8c4eab9f3e5 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.GeometriesEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Geometrycollection public readonly partial struct GeometriesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public GeometriesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.Mutable.cs index 68bed71ba25..b6d66cdba80 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.Mutable.cs @@ -350,6 +350,31 @@ public void SetType(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Geometryco _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.TypeEntity.cs index 45a1581d29e..76cb02457f3 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.cs index ba274f8bf8c..291d4c8fe38 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Geometrycollection.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public Geometrycollection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.ScalarExpressionArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.ScalarExpressionArray.cs index 6957b003833..a466585a521 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.ScalarExpressionArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.ScalarExpressionArray.cs @@ -23,11 +23,13 @@ public readonly partial struct InListOperands public readonly partial struct ScalarExpressionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ScalarExpressionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.cs index f96699a41c2..e5f0507549e 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InListOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct InListOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public InListOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantInstance.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantInstance.cs index 3666928de1c..8a77e463a1b 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantInstance.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantInstance.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public InstantInstance Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantString.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantString.cs index 7a584783c02..4e55eee8d5f 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantString.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.InstantString.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public InstantString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.OneOf1Entity.cs index 39e4aa7f922..25fa4ad3790 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.OneOf1Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.cs index 4b16149b092..048be9ca127 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.IntervalArrayEntity.cs @@ -557,6 +557,12 @@ private void CheckValidInstance() public IntervalArrayEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.cs index f1abeecb1c1..57a9a966e6d 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct IntervalArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public IntervalArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.Mutable.cs index a42c1717e3e..0fb4bcd3841 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.Mutable.cs @@ -298,6 +298,31 @@ public void SetInterval(in Corvus.Cql2Benchmark.Current.Cql2Schema.Int _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.cs index 32aa4365d51..3ac33110bdc 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IntervalInstance.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public IntervalInstance Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.IsBetweenOperandsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.IsBetweenOperandsEntity.cs index 648a6ac97ca..d8615439a97 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.IsBetweenOperandsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.IsBetweenOperandsEntity.cs @@ -587,6 +587,12 @@ private void CheckValidInstance() public IsBetweenOperandsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.cs index 9bebd1958aa..12a541ab4d4 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct IsBetweenOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public IsBetweenOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.Mutable.cs index 61b83dfc2a5..511c776b5e3 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.IsBetweenPre _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.OpEntity.cs index fbc69091ded..a8bf490c8b3 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.cs index 49641c7efd0..7ea5fa6a253 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsBetweenPredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public IsBetweenPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.Mutable.cs index fdfca318015..406644c675a 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.IsInListPred _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.OpEntity.cs index d5c07af3743..5b8faa38715 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.cs index 9c936f32fb3..ff21ad0745f 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsInListPredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public IsInListPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.PrefixItems0Entity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.PrefixItems0Entity.cs index d9839098669..0bad4c90dfa 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.PrefixItems0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.PrefixItems0Entity.cs @@ -530,6 +530,12 @@ private void CheckValidInstance() public PrefixItems0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.cs index 1d0cd6c55ee..ff1935452cd 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikeOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct IsLikeOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public IsLikeOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.Mutable.cs index eaa5d479665..065eba7104d 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.IsLikePredic _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.OpEntity.cs index ec9f659e629..7ef2c6ccae7 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.cs index 01f2068d2b4..bce636ef903 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsLikePredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public IsLikePredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.IsNullOperandEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.IsNullOperandEntity.cs index c26640d8dcd..e29a77c5c90 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.IsNullOperandEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.IsNullOperandEntity.cs @@ -1493,6 +1493,12 @@ private void CheckValidInstance() public IsNullOperandEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.cs index df69619da40..a65375e2d9c 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullOperand.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct IsNullOperand #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public IsNullOperand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.Mutable.cs index e54e0509f53..734954d2a92 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.IsNullPredic _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.OpEntity.cs index afbfac6ee76..ba8e49fc7cf 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.cs index 3757e046857..6d4c49fbf19 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.IsNullPredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public IsNullPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.JsonNumberArray.cs index c89cdb20b16..686f64c4ee7 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.JsonNumberArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.cs index 298b59894e3..84da8dc4496 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct Linestring public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.JsonNumberArray.cs index b205bd7532a..9160343ba35 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Linestring public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.Mutable.cs index fdccbda8ff2..bfc20588e9d 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Linestring _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.TypeEntity.cs index 1109de2bce8..6ab0a6d9f22 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.cs index 02a36ffa9c3..94d916232d0 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Linestring.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public Linestring Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index ff40a7f394f..01c5aa55b78 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.cs index 6080abddb31..76b3c3b6c0c 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.ItemsArrayArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -316,6 +333,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.cs index a8c7880bf2f..9ea342a45ed 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct Multilinestring public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.JsonNumberArray.cs index 88e1d4901b0..24647526be5 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Multilinestring public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.Mutable.cs index a37c3623886..ae3a16c61ef 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Multilines _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.TypeEntity.cs index 2a6296c2373..76be5deb885 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.cs index 520d370671b..89b902bb5c3 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multilinestring.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public Multilinestring Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.JsonNumberArray.cs index f90ea5ba6b1..cda06509134 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.JsonNumberArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.cs index ac6809fd86c..9a86e1b5707 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct Multipoint public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.JsonNumberArray.cs index 183924c987b..fc6a5f1f9ca 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Multipoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.Mutable.cs index ff471fb0258..b971bc16f8a 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Multipoint _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.TypeEntity.cs index a03700337b7..faeac331147 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.cs index e151eaa4bda..7e7f47ee1f9 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipoint.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public Multipoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs index ed74e3cb2cc..fff9c5a0f38 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct ItemsArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs index c804800cace..eec7e81e1d7 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs @@ -27,11 +27,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct ItemsArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public ItemsArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 7a9606baed1..c25f83307d7 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -316,6 +333,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.cs index 6d8cebb44be..1ceccf7d6ed 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct Multipolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.JsonNumberArray.cs index e6de77d0965..7119d1e2f29 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Multipolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.Mutable.cs index 15919d4d2c6..abda2aa6735 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Multipolyg _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.TypeEntity.cs index 5aba7958360..f3122bb88c8 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.cs index d3b419e975e..763271b616d 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Multipolygon.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public Multipolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Cql2SchemaArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Cql2SchemaArray.cs index 00a00b09415..f1c7a9cf847 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Cql2SchemaArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Cql2SchemaArray.cs @@ -23,11 +23,13 @@ public readonly partial struct NotExpression public readonly partial struct Cql2SchemaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -92,6 +94,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -305,6 +322,12 @@ private void CheckValidInstance() public Cql2SchemaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Mutable.cs index 30f1b849345..ee347211cd5 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.NotExpressio _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.OpEntity.cs index 3506a3bc765..1e74358de34 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.cs index 99d31888fce..b4216b7565f 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NotExpression.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public NotExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NumericExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NumericExpression.cs index fa708efd945..a1ad288a649 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NumericExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.NumericExpression.cs @@ -504,6 +504,12 @@ private void CheckValidInstance() public NumericExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.Mutable.cs index e509b96cc23..58ccec47a8b 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.Mutable.cs @@ -352,6 +352,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.PatternExpre _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.OpEntity.cs index 53a9b6433b3..45da2d7bf7e 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.OpEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.PatternExpressionArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.PatternExpressionArray.cs index 726b996577a..bb2c491f872 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.PatternExpressionArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.PatternExpressionArray.cs @@ -25,11 +25,13 @@ public readonly partial struct PatternExpressionRequiredArgsAndOp public readonly partial struct PatternExpressionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public PatternExpressionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.cs index 2f00de35d9c..27e6a5bccad 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.PatternExpressionRequiredArgsAndOp.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public PatternExpressionRequiredArgsAndOp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.Mutable.cs index 8bc6bcb3114..a2db2bf5603 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.Mutable.cs @@ -352,6 +352,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.PatternExpre _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.OpEntity.cs index 32eecc5494e..a728e5a9c34 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.OpEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.PatternExpressionArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.PatternExpressionArray.cs index 84088d5f50a..6fb12834bbd 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.PatternExpressionArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.PatternExpressionArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RequiredArgsAndOp public readonly partial struct PatternExpressionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public PatternExpressionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.cs index 4c6c7bbab23..d858c1b6144 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.RequiredArgsAndOp.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredArgsAndOp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.cs index e06cb1fe60c..a5e8c971402 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PatternExpression.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public PatternExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.CoordinateArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.CoordinateArray.cs index 920a4db2e63..fc7228e0a19 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.CoordinateArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.CoordinateArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Point public readonly partial struct CoordinateArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public CoordinateArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.JsonNumberArray.cs index 2472be4311f..8735fcdd7a3 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Point public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.Mutable.cs index ebe5f6acdaf..c83f8ff3948 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Point.Type _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.TypeEntity.cs index 02ddb49e7bc..dd558424887 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.cs index eb9a4fd871e..9829cb249dd 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Point.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public Point Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 0061499c60e..b1e34cf7757 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.cs index afb113579e7..130fbcd4abd 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -316,6 +333,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.cs index 4c06d5fe57d..b9b4ec5b7c6 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct Polygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.JsonNumberArray.cs index b3bfa7f4348..a96f0beee40 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Polygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.Mutable.cs index 650812517cd..bf4387d4297 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Polygon.Ty _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.TypeEntity.cs index 53afc0f4b95..ab879daf45b 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.cs index eb4920f8807..c4437d1e14b 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.Polygon.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public Polygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.Mutable.cs index a168ec2cdad..b062c7ac352 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.Mutable.cs @@ -264,6 +264,31 @@ public void SetProperty(scoped in Corvus.Cql2Benchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.cs index 7dfe02373e8..31e96051f4f 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.PropertyRef.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public PropertyRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarExpression.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarExpression.cs index 3defc05e357..46e4d7ba812 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarExpression.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarExpression.cs @@ -843,6 +843,12 @@ private void CheckValidInstance() public ScalarExpression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarOperands.cs index 522ed5ddbdf..7aab93e8ada 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.ScalarOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct ScalarOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public ScalarOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialInstance.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialInstance.cs index c6fd9c1ba12..66ab098b30e 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialInstance.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialInstance.cs @@ -582,6 +582,12 @@ private void CheckValidInstance() public SpatialInstance Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.SpatialOperandsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.SpatialOperandsEntity.cs index 8bc59bbb515..3c033523498 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.SpatialOperandsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.SpatialOperandsEntity.cs @@ -665,6 +665,12 @@ private void CheckValidInstance() public SpatialOperandsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.cs index 9aef2b851b1..10e70c8a311 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct SpatialOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public SpatialOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.Mutable.cs index 76a9b64fa92..1987f784270 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.SpatialPredi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.OpEntity.cs index ebf1edcd7d1..872098f2ae6 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.cs index 117400aed20..339be387a37 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.SpatialPredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public SpatialPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalInstance.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalInstance.cs index 5373c7d6ecb..fa685b6b1a5 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalInstance.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalInstance.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public TemporalInstance Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.TemporalOperandsEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.TemporalOperandsEntity.cs index b7112027b11..0bcdfeedb0d 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.TemporalOperandsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.TemporalOperandsEntity.cs @@ -530,6 +530,12 @@ private void CheckValidInstance() public TemporalOperandsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.cs index f618f21c1a1..19a5f0acb45 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalOperands.cs @@ -21,11 +21,13 @@ public readonly partial struct Cql2Schema public readonly partial struct TemporalOperands #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public TemporalOperands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.Mutable.cs index 9973ea2a197..031dd04679d 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.Mutable.cs @@ -350,6 +350,31 @@ public void SetOp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.TemporalPred _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.OpEntity.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.OpEntity.cs index 29d974d91b8..afe6473b30f 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.OpEntity.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.OpEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.cs index 46985d7c915..e4248954481 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TemporalPredicate.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public TemporalPredicate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.Mutable.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.Mutable.cs index e36e61dc81a..d0ed61c667a 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.Mutable.cs @@ -264,6 +264,31 @@ public void SetTimestamp(scoped in Corvus.Cql2Benchmark.Current.Cql2Schema.Times _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.cs index 54e782545fe..9e9b512754e 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampInstant.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public TimestampInstant Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampString.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampString.cs index ba59387b1e8..b151d21bb69 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampString.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.TimestampString.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public TimestampString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.cs index f88725a9b73..8189078f3ce 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/Cql2Schema.cs @@ -702,6 +702,12 @@ private void CheckValidInstance() public Cql2Schema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonBoolean.cs index 11a04fab411..58cdbe5bf92 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonNumber.cs index 432df599cd9..de8820f3b51 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonNumber.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonString.cs index 57b5f3c3ea6..388d7b3724b 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/corvusjson-jsonschema.lock index 945cbc921b6..aa31dc8ddeb 100644 --- a/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.Cql2BenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:20.3131463\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:52.1345866\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.AllowCompoundWordsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.AllowCompoundWordsEntity.cs index cdb52295e36..79403cd7914 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.AllowCompoundWordsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.AllowCompoundWordsEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public AllowCompoundWordsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheFormat.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheFormat.cs index 923c15f6d9c..3af1802f13e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheFormat.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheFormat.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public CacheFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.Mutable.cs index fad68ea32b8..42cfe628b93 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.Mutable.cs @@ -424,6 +424,36 @@ public bool RemoveUseCache() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseCacheUtf8, out IJsonDocument? _, out int _)) + { + SetUseCache(Corvus.CspellBenchmark.Current.CspellSchema.CacheSettings.UseCacheEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.UseCacheEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.UseCacheEntity.cs index 161ee854b2a..a5dd0bbd019 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.UseCacheEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.UseCacheEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public UseCacheEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.cs index 905be25a3fe..dd21d639c75 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheSettings.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public CacheSettings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheStrategy.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheStrategy.cs index 11c9ff231e9..83f4bb41f5e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheStrategy.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CacheStrategy.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public CacheStrategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CaseSensitiveEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CaseSensitiveEntity.cs index 6b98badb07c..c724a22752e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CaseSensitiveEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CaseSensitiveEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public CaseSensitiveEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.Mutable.cs index bd31e08a808..ada83a4bb1d 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.Mutable.cs @@ -330,6 +330,31 @@ public bool RemovePenalty() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.cs index 4535ab56c0d..62b5081fd9b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CharacterSetCosts.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public CharacterSetCosts Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.Mutable.cs index 92aa1805aaf..4ff285da8f1 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.Mutable.cs @@ -540,6 +540,31 @@ public bool RemoveSwap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.cs index 8454bd514b8..20445e5a35a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefInsDel.cs @@ -425,6 +425,12 @@ private void CheckValidInstance() public CostMapDefInsDel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.Mutable.cs index 805b99da407..2114ce6bf5e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.Mutable.cs @@ -540,6 +540,31 @@ public bool RemoveSwap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.cs index c9433bfc301..79e78035543 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefReplace.cs @@ -425,6 +425,12 @@ private void CheckValidInstance() public CostMapDefReplace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.Mutable.cs index 7346f97552f..5122a6c826a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.Mutable.cs @@ -540,6 +540,31 @@ public void SetSwap(scoped in Corvus.CspellBenchmark.Current.JsonNumber.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.cs index 37298785c2b..2160d0d6c00 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CostMapDefSwap.cs @@ -425,6 +425,12 @@ private void CheckValidInstance() public CostMapDefSwap Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CustomDictionaryScope.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CustomDictionaryScope.cs index da0fd0f1c8e..e3cfc6c4fa8 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CustomDictionaryScope.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.CustomDictionaryScope.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public CustomDictionaryScope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinition.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinition.cs index c5290155d0f..0d422f83aa3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinition.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinition.cs @@ -555,6 +555,12 @@ private void CheckValidInstance() public DictionaryDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.Mutable.cs index 837720e1a39..76c75c4a7d8 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.Mutable.cs @@ -675,6 +675,31 @@ public bool RemoveUseCompounds() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.cs index 8e82931dc2c..524f0d73388 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAlternate.cs @@ -484,6 +484,12 @@ private void CheckValidInstance() public DictionaryDefinitionAlternate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionArray.cs index 1f7027fc27f..9694f59385b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionArray.cs @@ -32,11 +32,13 @@ public readonly partial struct CspellSchema public readonly partial struct DictionaryDefinitionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public DictionaryDefinitionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.Mutable.cs index c1cfcc771d4..24a1ab3d15b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.Mutable.cs @@ -780,6 +780,37 @@ public bool RemoveUseCompounds() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DictionaryInformationValueUtf8, out Corvus.CspellBenchmark.Current.CspellSchema.DictionaryInformation.Mutable __corvusDictionaryInformationValue)) + { + __corvusDictionaryInformationValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.cs index 1d627d30312..d949a8118a3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionAugmented.cs @@ -508,6 +508,12 @@ private void CheckValidInstance() public DictionaryDefinitionAugmented Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.Mutable.cs index 6729a3fc076..0cdedb26fe8 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.Mutable.cs @@ -835,6 +835,31 @@ public bool RemoveUseCompounds() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.CustomDictionaryScopeArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.CustomDictionaryScopeArray.cs index 01c21579804..b2dd7f1f43a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.CustomDictionaryScopeArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.CustomDictionaryScopeArray.cs @@ -25,11 +25,13 @@ public readonly partial struct ScopeEntity public readonly partial struct CustomDictionaryScopeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public CustomDictionaryScopeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.cs index e324ceae892..65710164c45 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.ScopeEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public ScopeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.cs index f839d83c662..a45506cf0cd 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionCustom.cs @@ -535,6 +535,12 @@ private void CheckValidInstance() public DictionaryDefinitionCustom Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInline.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInline.cs index ce34e6c6cf6..e498345ff16 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInline.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInline.cs @@ -425,6 +425,12 @@ private void CheckValidInstance() public DictionaryDefinitionInline Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.IgnoreWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.IgnoreWordArray.cs index 98b49f7e9b0..d857fbbafc5 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.IgnoreWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.IgnoreWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct DictionaryDefinitionInlineFlagWords public readonly partial struct IgnoreWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public IgnoreWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.JsonStringArray.cs index ec421e596ed..7f3e4066ffe 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.JsonStringArray.cs @@ -40,11 +40,13 @@ public readonly partial struct DictionaryDefinitionInlineFlagWords public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.ListOfWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.ListOfWordArray.cs index bf7aef44b8e..1432413aff3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.ListOfWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.ListOfWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct DictionaryDefinitionInlineFlagWords public readonly partial struct ListOfWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.Mutable.cs index ac3b0b27b76..8759ec4e0f7 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.Mutable.cs @@ -1033,6 +1033,31 @@ public bool RemoveWords() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.SuggestWorArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.SuggestWorArray.cs index 1eb4057440e..14841de5497 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.SuggestWorArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.SuggestWorArray.cs @@ -37,11 +37,13 @@ public readonly partial struct DictionaryDefinitionInlineFlagWords public readonly partial struct SuggestWorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public SuggestWorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.cs index 82ff73ced88..59bd52edcee 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineFlagWords.cs @@ -560,6 +560,12 @@ private void CheckValidInstance() public DictionaryDefinitionInlineFlagWords Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.IgnoreWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.IgnoreWordArray.cs index 7a19b978ec2..11ded1ab76b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.IgnoreWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.IgnoreWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct DictionaryDefinitionInlineIgnoreWords public readonly partial struct IgnoreWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public IgnoreWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.JsonStringArray.cs index f82d85db40b..927333b1f71 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.JsonStringArray.cs @@ -40,11 +40,13 @@ public readonly partial struct DictionaryDefinitionInlineIgnoreWords public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.ListOfWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.ListOfWordArray.cs index 8632e94233e..1856b7712ae 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.ListOfWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.ListOfWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct DictionaryDefinitionInlineIgnoreWords public readonly partial struct ListOfWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.Mutable.cs index c9bfbf62cc4..acd56464b2b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.Mutable.cs @@ -1033,6 +1033,31 @@ public bool RemoveWords() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.SuggestWorArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.SuggestWorArray.cs index e3e4808d76d..c624d167fe0 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.SuggestWorArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.SuggestWorArray.cs @@ -37,11 +37,13 @@ public readonly partial struct DictionaryDefinitionInlineIgnoreWords public readonly partial struct SuggestWorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public SuggestWorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.cs index dcfe7fbab0e..56b2b27f787 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineIgnoreWords.cs @@ -560,6 +560,12 @@ private void CheckValidInstance() public DictionaryDefinitionInlineIgnoreWords Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.IgnoreWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.IgnoreWordArray.cs index 5ed90caa130..6b2e24aac97 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.IgnoreWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.IgnoreWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct DictionaryDefinitionInlineWords public readonly partial struct IgnoreWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public IgnoreWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.JsonStringArray.cs index 490917748ab..b53324ab21e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.JsonStringArray.cs @@ -40,11 +40,13 @@ public readonly partial struct DictionaryDefinitionInlineWords public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.ListOfWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.ListOfWordArray.cs index 8829d871c74..83aacd217cf 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.ListOfWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.ListOfWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct DictionaryDefinitionInlineWords public readonly partial struct ListOfWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.Mutable.cs index 7175c0a904e..38e7188cf21 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.Mutable.cs @@ -1033,6 +1033,31 @@ public void SetWords(in Corvus.CspellBenchmark.Current.CspellSchema.Di _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.SuggestWorArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.SuggestWorArray.cs index b2176fada58..2c82d0cc694 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.SuggestWorArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.SuggestWorArray.cs @@ -37,11 +37,13 @@ public readonly partial struct DictionaryDefinitionInlineWords public readonly partial struct SuggestWorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public SuggestWorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.cs index b03006cf410..84288fd779f 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionInlineWords.cs @@ -560,6 +560,12 @@ private void CheckValidInstance() public DictionaryDefinitionInlineWords Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.Mutable.cs index ad235b7f91d..e87c72c10bc 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.Mutable.cs @@ -675,6 +675,31 @@ public bool RemoveUseCompounds() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.cs index a6da8de40e4..5735c6b62d8 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryDefinitionPreferred.cs @@ -479,6 +479,12 @@ private void CheckValidInstance() public DictionaryDefinitionPreferred Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryFileTypes.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryFileTypes.cs index 46e13eb6049..422b231fa74 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryFileTypes.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryFileTypes.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public DictionaryFileTypes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryId.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryId.cs index e5d3a1fcbc9..badf9c0df09 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryId.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryId.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public DictionaryId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.Mutable.cs index 62d46a1abc5..ac6cb7addd0 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.Mutable.cs @@ -901,6 +901,48 @@ public bool RemoveSuggestionEditCosts() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AlphabetUtf8, out IJsonDocument? _, out int _)) + { + SetAlphabet(Corvus.CspellBenchmark.Current.CspellSchema.DictionaryInformation.TheAlphabetToUse.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CostsUtf8, out Corvus.CspellBenchmark.Current.CspellSchema.EditCosts.Mutable __corvusCosts)) + { + __corvusCosts.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HunspellInformationValueUtf8, out Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.Mutable __corvusHunspellInformationValue)) + { + __corvusHunspellInformationValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.PatternAdjustmentArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.PatternAdjustmentArray.cs index 580c03edbf2..0c0f837c7ab 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.PatternAdjustmentArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.PatternAdjustmentArray.cs @@ -28,11 +28,13 @@ public readonly partial struct DictionaryInformation public readonly partial struct PatternAdjustmentArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public PatternAdjustmentArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.CharacterSetCostsArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.CharacterSetCostsArray.cs index 30f04964e4f..4fd2dace1d3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.CharacterSetCostsArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.CharacterSetCostsArray.cs @@ -25,11 +25,13 @@ public readonly partial struct TheAccentCharactersDefaultU0300U0341 public readonly partial struct CharacterSetCostsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public CharacterSetCostsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.cs index 20005adeebb..6d9408e58da 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAccentCharactersDefaultU0300U0341.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheAccentCharactersDefaultU0300U0341 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.CharacterSetCostsArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.CharacterSetCostsArray.cs index aed81890497..9e2043d88d3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.CharacterSetCostsArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.CharacterSetCostsArray.cs @@ -25,11 +25,13 @@ public readonly partial struct TheAlphabetToUse public readonly partial struct CharacterSetCostsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public CharacterSetCostsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.cs index f8cef62f33f..b3d57dd605f 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.TheAlphabetToUse.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public TheAlphabetToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.cs index b71b78dd7db..4f0dcef7dd9 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryInformation.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public DictionaryInformation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryNegRef.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryNegRef.cs index 4b5567730d3..46f8a449fa2 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryNegRef.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryNegRef.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public DictionaryNegRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryPath.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryPath.cs index 9ae3aff754e..d6e7a62689d 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryPath.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryPath.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DictionaryPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReference.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReference.cs index 502242bfd39..fa77e14d606 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReference.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReference.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public DictionaryReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReferenceArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReferenceArray.cs index e06ab225e94..520e82889ef 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReferenceArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.DictionaryReferenceArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CspellSchema public readonly partial struct DictionaryReferenceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public DictionaryReferenceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.AccentCostsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.AccentCostsEntity.cs index bdeeff521cc..c3647b96ccf 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.AccentCostsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.AccentCostsEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public AccentCostsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.CapsCostsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.CapsCostsEntity.cs index 351a53fe421..66d245e9fdb 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.CapsCostsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.CapsCostsEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public CapsCostsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.FirstLetterPenaltyEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.FirstLetterPenaltyEntity.cs index f3c07d0c0f3..c13b395e624 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.FirstLetterPenaltyEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.FirstLetterPenaltyEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public FirstLetterPenaltyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.Mutable.cs index 2cf8dbcf034..79e0afd91ad 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.Mutable.cs @@ -469,6 +469,56 @@ public bool RemoveNonAlphabetCosts() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AccentCostsUtf8, out IJsonDocument? _, out int _)) + { + SetAccentCosts(Corvus.CspellBenchmark.Current.CspellSchema.EditCosts.AccentCostsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BaseCostUtf8, out IJsonDocument? _, out int _)) + { + SetBaseCost(Corvus.CspellBenchmark.Current.CspellSchema.EditCosts.ThisIsTheBaseCostForMakingAnEdit.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CapsCostsUtf8, out IJsonDocument? _, out int _)) + { + SetCapsCosts(Corvus.CspellBenchmark.Current.CspellSchema.EditCosts.CapsCostsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FirstLetterPenaltyUtf8, out IJsonDocument? _, out int _)) + { + SetFirstLetterPenalty(Corvus.CspellBenchmark.Current.CspellSchema.EditCosts.FirstLetterPenaltyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NonAlphabetCostsUtf8, out IJsonDocument? _, out int _)) + { + SetNonAlphabetCosts(Corvus.CspellBenchmark.Current.CspellSchema.EditCosts.ThisIsTheCostForCharactersNotInTheAlphabet.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheBaseCostForMakingAnEdit.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheBaseCostForMakingAnEdit.cs index 8c5295c46c8..82319fe2484 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheBaseCostForMakingAnEdit.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheBaseCostForMakingAnEdit.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ThisIsTheBaseCostForMakingAnEdit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheCostForCharactersNotInTheAlphabet.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheCostForCharactersNotInTheAlphabet.cs index 412bab1bde1..2c9b8a799fd 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheCostForCharactersNotInTheAlphabet.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.ThisIsTheCostForCharactersNotInTheAlphabet.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ThisIsTheCostForCharactersNotInTheAlphabet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.cs index f7cd1429b1e..d685ae834a2 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EditCosts.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public EditCosts Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EnableGlobDotEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EnableGlobDotEntity.cs index 5aa4a778f33..b7fcf0faf8a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EnableGlobDotEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.EnableGlobDotEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public EnableGlobDotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FailFastEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FailFastEntity.cs index 8d00b24cb7f..b810ab2ee95 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FailFastEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FailFastEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public FailFastEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.Mutable.cs index f62f4cb64ac..6531425dc54 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.Mutable.cs @@ -205,6 +205,31 @@ public bool RemoveWeightedSuggestions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.cs index c46ce44977b..2445b983f09 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Features.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public Features Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FlagWordsJArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FlagWordsJArray.cs index 483c8d3aae8..0415b3d34c9 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FlagWordsJArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.FlagWordsJArray.cs @@ -38,11 +38,13 @@ public readonly partial struct CspellSchema public readonly partial struct FlagWordsJArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -92,6 +94,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -305,6 +322,12 @@ private void CheckValidInstance() public FlagWordsJArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.JsonStringArray.cs index 93700a82666..19cdcffcc2a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GitignoreRootEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.cs index f2d3e97ab0b..671041db94a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.GitignoreRootEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public GitignoreRootEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.Mutable.cs index e32283944ba..559961057de 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.Mutable.cs @@ -320,6 +320,37 @@ public bool RemoveCosts() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CostsUtf8, out Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.Mutable __corvusCosts)) + { + __corvusCosts.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.AccentCostsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.AccentCostsEntity.cs index a86e789e694..f0c7fc94a98 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.AccentCostsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.AccentCostsEntity.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public AccentCostsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.CapsCostsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.CapsCostsEntity.cs index e7d7e66f96b..f052979f4e7 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.CapsCostsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.CapsCostsEntity.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public CapsCostsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.FirstLetterPenaltyEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.FirstLetterPenaltyEntity.cs index 06c3ccacf97..44f77cde3f2 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.FirstLetterPenaltyEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.FirstLetterPenaltyEntity.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public FirstLetterPenaltyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.IoConvertCostEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.IoConvertCostEntity.cs index 2f18776a53e..73948ab9d1f 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.IoConvertCostEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.IoConvertCostEntity.cs @@ -417,6 +417,12 @@ private void CheckValidInstance() public IoConvertCostEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.KeyboardCostEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.KeyboardCostEntity.cs index 3004cc9d7d0..1d346dfa1a5 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.KeyboardCostEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.KeyboardCostEntity.cs @@ -417,6 +417,12 @@ private void CheckValidInstance() public KeyboardCostEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.MapCostEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.MapCostEntity.cs index df954885ce7..522e0add4a1 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.MapCostEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.MapCostEntity.cs @@ -417,6 +417,12 @@ private void CheckValidInstance() public MapCostEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.Mutable.cs index d04c47ecb0c..7edf7368826 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.Mutable.cs @@ -810,6 +810,76 @@ public bool RemoveTryCharCost() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AccentCostsUtf8, out IJsonDocument? _, out int _)) + { + SetAccentCosts(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.AccentCostsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BaseCostUtf8, out IJsonDocument? _, out int _)) + { + SetBaseCost(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheBaseCostForMakingAnEdit.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CapsCostsUtf8, out IJsonDocument? _, out int _)) + { + SetCapsCosts(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.CapsCostsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FirstLetterPenaltyUtf8, out IJsonDocument? _, out int _)) + { + SetFirstLetterPenalty(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.FirstLetterPenaltyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IoConvertCostUtf8, out IJsonDocument? _, out int _)) + { + SetIoConvertCost(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.IoConvertCostEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.KeyboardCostUtf8, out IJsonDocument? _, out int _)) + { + SetKeyboardCost(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.KeyboardCostEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MapCostUtf8, out IJsonDocument? _, out int _)) + { + SetMapCost(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.MapCostEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NonAlphabetCostsUtf8, out IJsonDocument? _, out int _)) + { + SetNonAlphabetCosts(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheCostForCharactersNotInTheAlphabet.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReplaceCostsUtf8, out IJsonDocument? _, out int _)) + { + SetReplaceCosts(Corvus.CspellBenchmark.Current.CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.TheCostToSubstitutePairsFoundInTheReplaceSettings.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.TheCostToSubstitutePairsFoundInTheReplaceSettings.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.TheCostToSubstitutePairsFoundInTheReplaceSettings.cs index 4831994dfcf..0dc0c98b961 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.TheCostToSubstitutePairsFoundInTheReplaceSettings.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.TheCostToSubstitutePairsFoundInTheReplaceSettings.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public TheCostToSubstitutePairsFoundInTheReplaceSettings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheBaseCostForMakingAnEdit.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheBaseCostForMakingAnEdit.cs index 7aa7ef8d36c..914413deee3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheBaseCostForMakingAnEdit.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheBaseCostForMakingAnEdit.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public ThisIsTheBaseCostForMakingAnEdit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheCostForCharactersNotInTheAlphabet.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheCostForCharactersNotInTheAlphabet.cs index e62bbef2bc7..4084311ccbc 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheCostForCharactersNotInTheAlphabet.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.ThisIsTheCostForCharactersNotInTheAlphabet.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public ThisIsTheCostForCharactersNotInTheAlphabet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.cs index be8f32a5f80..77700b59ce3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.TheCostsToApplyWhenUsingTheHunspellSettings.cs @@ -492,6 +492,12 @@ private void CheckValidInstance() public TheCostsToApplyWhenUsingTheHunspellSettings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.cs index deeb42a0564..6508e37f937 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.HunspellInformation.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public HunspellInformation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnorePathArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnorePathArray.cs index f2fdf3e6042..050c99ec998 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnorePathArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnorePathArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CspellSchema public readonly partial struct IgnorePathArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public IgnorePathArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnoreWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnoreWordArray.cs index a8f57759bb9..aef5d2e15f0 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnoreWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IgnoreWordArray.cs @@ -26,11 +26,13 @@ public readonly partial struct CspellSchema public readonly partial struct IgnoreWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public IgnoreWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.JsonStringArray.cs index 485f9b110cc..87d2e133e2b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ImportEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.cs index 04ae4dc4081..049a2c1a2be 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ImportEntity.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public ImportEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IsTheSpellCheckerEnabled.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IsTheSpellCheckerEnabled.cs index 451f39ea1d9..90cf93cbcdd 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IsTheSpellCheckerEnabled.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.IsTheSpellCheckerEnabled.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IsTheSpellCheckerEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.JsonStringArray.cs index 1996ac88955..b855ae6ab40 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.JsonStringArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CspellSchema public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageId.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageId.cs index ae98a2ad887..b1d71e621a8 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageId.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageId.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public LanguageId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultiple.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultiple.cs index 74192f509cb..8bc93c94321 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultiple.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultiple.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public LanguageIdMultiple Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultipleNeg.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultipleNeg.cs index 064cacd3e7e..a327d1514e9 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultipleNeg.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdMultipleNeg.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public LanguageIdMultipleNeg Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingle.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingle.cs index ad68eb38971..6d3b4eaaddf 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingle.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingle.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public LanguageIdSingle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingleArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingleArray.cs index 45cc555b74c..0e297969ea8 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingleArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdSingleArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CspellSchema public readonly partial struct LanguageIdSingleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public LanguageIdSingleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdsForThArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdsForThArray.cs index 45607dd5792..35b3828c9a5 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdsForThArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageIdsForThArray.cs @@ -26,11 +26,13 @@ public readonly partial struct CspellSchema public readonly partial struct LanguageIdsForThArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public LanguageIdsForThArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.AllowCompoundWordsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.AllowCompoundWordsEntity.cs index c243977a1a0..422c71a7021 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.AllowCompoundWordsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.AllowCompoundWordsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AllowCompoundWordsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.CaseSensitiveEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.CaseSensitiveEntity.cs index 9a593272c8f..744386f200e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.CaseSensitiveEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.CaseSensitiveEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public CaseSensitiveEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryDefinitionArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryDefinitionArray.cs index f46579f7698..8ce776495dc 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryDefinitionArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryDefinitionArray.cs @@ -34,11 +34,13 @@ public readonly partial struct LanguageSetting public readonly partial struct DictionaryDefinitionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public DictionaryDefinitionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryReferenceArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryReferenceArray.cs index 00fe06620ef..5367c7f968c 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryReferenceArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.DictionaryReferenceArray.cs @@ -37,11 +37,13 @@ public readonly partial struct LanguageSetting public readonly partial struct DictionaryReferenceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public DictionaryReferenceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IgnoreWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IgnoreWordArray.cs index 15cb602398d..d6da90e0c64 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IgnoreWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IgnoreWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct LanguageSetting public readonly partial struct IgnoreWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public IgnoreWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IsTheSpellCheckerEnabled.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IsTheSpellCheckerEnabled.cs index 2037caf0306..41db84be893 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IsTheSpellCheckerEnabled.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.IsTheSpellCheckerEnabled.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IsTheSpellCheckerEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.JsonStringArray.cs index 7850318409b..abc95edb8ef 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.JsonStringArray.cs @@ -40,11 +40,13 @@ public readonly partial struct LanguageSetting public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.ListOfWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.ListOfWordArray.cs index b525fb322ac..8d2de344914 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.ListOfWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.ListOfWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct LanguageSetting public readonly partial struct ListOfWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.JsonStringArray.cs index 2662798291f..cb99a0ae81f 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.JsonStringArray.cs @@ -25,11 +25,13 @@ public readonly partial struct LocalEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.cs index 55c33e99832..fffbd837574 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocalEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public LocalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.JsonStringArray.cs index cc6f31b1a90..c852964fec6 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.JsonStringArray.cs @@ -25,11 +25,13 @@ public readonly partial struct LocaleEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.cs index a3359994672..c80437f21ae 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.LocaleEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public LocaleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.Mutable.cs index 04518ad009b..504ecec5ea9 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.Mutable.cs @@ -1932,6 +1932,46 @@ public bool RemoveWords() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowCompoundWordsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowCompoundWords(Corvus.CspellBenchmark.Current.CspellSchema.LanguageSetting.AllowCompoundWordsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CaseSensitiveUtf8, out IJsonDocument? _, out int _)) + { + SetCaseSensitive(Corvus.CspellBenchmark.Current.CspellSchema.LanguageSetting.CaseSensitiveEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.CspellBenchmark.Current.CspellSchema.LanguageSetting.IsTheSpellCheckerEnabled.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.NoSuggestDictionariArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.NoSuggestDictionariArray.cs index 1a90787ff3c..782471fd535 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.NoSuggestDictionariArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.NoSuggestDictionariArray.cs @@ -31,11 +31,13 @@ public readonly partial struct LanguageSetting public readonly partial struct NoSuggestDictionariArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public NoSuggestDictionariArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.RegExpPatternDefinitionArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.RegExpPatternDefinitionArray.cs index a5c3c0966af..3083ef5282e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.RegExpPatternDefinitionArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.RegExpPatternDefinitionArray.cs @@ -34,11 +34,13 @@ public readonly partial struct LanguageSetting public readonly partial struct RegExpPatternDefinitionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public RegExpPatternDefinitionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.SuggestWorArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.SuggestWorArray.cs index 1d1b9f3da73..608c5dba795 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.SuggestWorArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.SuggestWorArray.cs @@ -37,11 +37,13 @@ public readonly partial struct LanguageSetting public readonly partial struct SuggestWorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public SuggestWorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.cs index 94d6e7bd3cb..c059d69c80f 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSetting.cs @@ -752,6 +752,12 @@ private void CheckValidInstance() public LanguageSetting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSettingArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSettingArray.cs index 3e0d46e25a9..1bfad418556 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LanguageSettingArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CspellSchema public readonly partial struct LanguageSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public LanguageSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ListOfWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ListOfWordArray.cs index e9cbdcd7f38..9bc6e376a4e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ListOfWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ListOfWordArray.cs @@ -26,11 +26,13 @@ public readonly partial struct CspellSchema public readonly partial struct ListOfWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ListOfWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LoadDefaultConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LoadDefaultConfigurationEntity.cs index 38c920e4a09..21cc830c80b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LoadDefaultConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.LoadDefaultConfigurationEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public LoadDefaultConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.LanguageIdArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.LanguageIdArray.cs index d83529f63ae..38f2068e865 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.LanguageIdArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.LanguageIdArray.cs @@ -23,11 +23,13 @@ public readonly partial struct MatchingFileType public readonly partial struct LanguageIdArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public LanguageIdArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.cs index b1daf78e3a5..e67e92c7c92 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MatchingFileType.cs @@ -472,6 +472,12 @@ private void CheckValidInstance() public MatchingFileType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MaxDuplicateProblemsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MaxDuplicateProblemsEntity.cs index c139e727c02..6140fda0192 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MaxDuplicateProblemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MaxDuplicateProblemsEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public MaxDuplicateProblemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MinWordLengthEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MinWordLengthEntity.cs index 6a95383224e..52e6b8d84c6 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MinWordLengthEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.MinWordLengthEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public MinWordLengthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Mutable.cs index 992c013b0a4..2d647a52434 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Mutable.cs @@ -4472,6 +4472,138 @@ public bool RemoveWords() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SchemaUtf8, out IJsonDocument? _, out int _)) + { + SetSchema(Corvus.CspellBenchmark.Current.CspellSchema.UrlToJsonSchema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowCompoundWordsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowCompoundWords(Corvus.CspellBenchmark.Current.CspellSchema.AllowCompoundWordsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CaseSensitiveUtf8, out IJsonDocument? _, out int _)) + { + SetCaseSensitive(Corvus.CspellBenchmark.Current.CspellSchema.CaseSensitiveEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableGlobDotUtf8, out IJsonDocument? _, out int _)) + { + SetEnableGlobDot(Corvus.CspellBenchmark.Current.CspellSchema.EnableGlobDotEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.CspellBenchmark.Current.CspellSchema.IsTheSpellCheckerEnabled.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FailFastUtf8, out IJsonDocument? _, out int _)) + { + SetFailFast(Corvus.CspellBenchmark.Current.CspellSchema.FailFastEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LoadDefaultConfigurationUtf8, out IJsonDocument? _, out int _)) + { + SetLoadDefaultConfiguration(Corvus.CspellBenchmark.Current.CspellSchema.LoadDefaultConfigurationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxDuplicateProblemsUtf8, out IJsonDocument? _, out int _)) + { + SetMaxDuplicateProblems(Corvus.CspellBenchmark.Current.CspellSchema.MaxDuplicateProblemsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxNumberOfProblemsUtf8, out IJsonDocument? _, out int _)) + { + SetMaxNumberOfProblems(Corvus.CspellBenchmark.Current.CspellSchema.TheMaximumNumberOfProblemsToReportInAFile.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinWordLengthUtf8, out IJsonDocument? _, out int _)) + { + SetMinWordLength(Corvus.CspellBenchmark.Current.CspellSchema.MinWordLengthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoConfigSearchUtf8, out IJsonDocument? _, out int _)) + { + SetNoConfigSearch(Corvus.CspellBenchmark.Current.CspellSchema.NoConfigSearchEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NumSuggestionsUtf8, out IJsonDocument? _, out int _)) + { + SetNumSuggestions(Corvus.CspellBenchmark.Current.CspellSchema.NumberOfSuggestionsToMake.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PnpFilesUtf8, out IJsonDocument? _, out int _)) + { + SetPnpFiles(Corvus.CspellBenchmark.Current.CspellSchema.PnpFilesJsArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReadonlyUtf8, out IJsonDocument? _, out int _)) + { + SetReadonly(Corvus.CspellBenchmark.Current.CspellSchema.ReadonlyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReportersUtf8, out IJsonDocument? _, out int _)) + { + SetReporters(Corvus.CspellBenchmark.Current.CspellSchema.ReporterSettingsArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuggestionNumChangesUtf8, out IJsonDocument? _, out int _)) + { + SetSuggestionNumChanges(Corvus.CspellBenchmark.Current.CspellSchema.SuggestionNumChangesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuggestionsTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetSuggestionsTimeout(Corvus.CspellBenchmark.Current.CspellSchema.SuggestionsTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseGitignoreUtf8, out IJsonDocument? _, out int _)) + { + SetUseGitignore(Corvus.CspellBenchmark.Current.CspellSchema.UseGitignoreEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UsePnPUtf8, out IJsonDocument? _, out int _)) + { + SetUsePnP(Corvus.CspellBenchmark.Current.CspellSchema.UsePnPEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CacheUtf8, out Corvus.CspellBenchmark.Current.CspellSchema.CacheSettings.Mutable __corvusCache)) + { + __corvusCache.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FeaturesValueUtf8, out Corvus.CspellBenchmark.Current.CspellSchema.Features.Mutable __corvusFeaturesValue)) + { + __corvusFeaturesValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoConfigSearchEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoConfigSearchEntity.cs index 73a22158886..813f9306fcd 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoConfigSearchEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoConfigSearchEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public NoConfigSearchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoSuggestDictionariArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoSuggestDictionariArray.cs index 8b2b6e1ce19..dcfaa235609 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoSuggestDictionariArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NoSuggestDictionariArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CspellSchema public readonly partial struct NoSuggestDictionariArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public NoSuggestDictionariArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NumberOfSuggestionsToMake.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NumberOfSuggestionsToMake.cs index 75859196d6b..a5367a5a333 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NumberOfSuggestionsToMake.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.NumberOfSuggestionsToMake.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public NumberOfSuggestionsToMake Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.AllowCompoundWordsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.AllowCompoundWordsEntity.cs index 9cd9f5c345b..2b05af224da 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.AllowCompoundWordsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.AllowCompoundWordsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AllowCompoundWordsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.CaseSensitiveEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.CaseSensitiveEntity.cs index 2782691e52d..918f3a5ca1a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.CaseSensitiveEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.CaseSensitiveEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public CaseSensitiveEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryDefinitionArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryDefinitionArray.cs index 8b8ef8303a6..a9c586db257 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryDefinitionArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryDefinitionArray.cs @@ -34,11 +34,13 @@ public readonly partial struct OverrideSettings public readonly partial struct DictionaryDefinitionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public DictionaryDefinitionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryReferenceArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryReferenceArray.cs index 2219b8d125e..f63eac6ad4c 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryReferenceArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.DictionaryReferenceArray.cs @@ -37,11 +37,13 @@ public readonly partial struct OverrideSettings public readonly partial struct DictionaryReferenceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public DictionaryReferenceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.JsonStringArray.cs index 55a36ab5e08..d6a4a5df847 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.JsonStringArray.cs @@ -25,11 +25,13 @@ public readonly partial struct GlobPatternOrPatternsToMatchAgainst public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.cs index 07c45e25ecb..b6208db3128 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.GlobPatternOrPatternsToMatchAgainst.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public GlobPatternOrPatternsToMatchAgainst Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IgnoreWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IgnoreWordArray.cs index 597d8bd0742..ae39a9eef50 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IgnoreWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IgnoreWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct OverrideSettings public readonly partial struct IgnoreWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public IgnoreWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IsTheSpellCheckerEnabled.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IsTheSpellCheckerEnabled.cs index 0263e0ab8b1..af63aef1458 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IsTheSpellCheckerEnabled.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.IsTheSpellCheckerEnabled.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IsTheSpellCheckerEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.JsonStringArray.cs index 19771d0d6d9..8a71b739fd0 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.JsonStringArray.cs @@ -40,11 +40,13 @@ public readonly partial struct OverrideSettings public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdSingleArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdSingleArray.cs index b4c868e7b50..cc5590d765a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdSingleArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdSingleArray.cs @@ -37,11 +37,13 @@ public readonly partial struct OverrideSettings public readonly partial struct LanguageIdSingleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public LanguageIdSingleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdsForThArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdsForThArray.cs index 4f2c400763f..7dc01a0c23b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdsForThArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageIdsForThArray.cs @@ -28,11 +28,13 @@ public readonly partial struct OverrideSettings public readonly partial struct LanguageIdsForThArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public LanguageIdsForThArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageSettingArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageSettingArray.cs index 817d18854fb..c34aceb908a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LanguageSettingArray.cs @@ -31,11 +31,13 @@ public readonly partial struct OverrideSettings public readonly partial struct LanguageSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public LanguageSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.ListOfWordArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.ListOfWordArray.cs index 0da713a26ad..2450507a2a6 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.ListOfWordArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.ListOfWordArray.cs @@ -28,11 +28,13 @@ public readonly partial struct OverrideSettings public readonly partial struct ListOfWordArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfWordArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LoadDefaultConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LoadDefaultConfigurationEntity.cs index db25909383e..e443c92843d 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LoadDefaultConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.LoadDefaultConfigurationEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public LoadDefaultConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MaxDuplicateProblemsEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MaxDuplicateProblemsEntity.cs index 4af91280b56..767789fc2e7 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MaxDuplicateProblemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MaxDuplicateProblemsEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public MaxDuplicateProblemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MinWordLengthEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MinWordLengthEntity.cs index d56018d5530..f3f0dd8c565 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MinWordLengthEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.MinWordLengthEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public MinWordLengthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.Mutable.cs index b03bc528a7d..124fa8104c4 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.Mutable.cs @@ -2857,6 +2857,91 @@ public bool RemoveWords() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowCompoundWordsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowCompoundWords(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.AllowCompoundWordsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CaseSensitiveUtf8, out IJsonDocument? _, out int _)) + { + SetCaseSensitive(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.CaseSensitiveEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.IsTheSpellCheckerEnabled.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LoadDefaultConfigurationUtf8, out IJsonDocument? _, out int _)) + { + SetLoadDefaultConfiguration(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.LoadDefaultConfigurationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxDuplicateProblemsUtf8, out IJsonDocument? _, out int _)) + { + SetMaxDuplicateProblems(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.MaxDuplicateProblemsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxNumberOfProblemsUtf8, out IJsonDocument? _, out int _)) + { + SetMaxNumberOfProblems(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.TheMaximumNumberOfProblemsToReportInAFile.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinWordLengthUtf8, out IJsonDocument? _, out int _)) + { + SetMinWordLength(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.MinWordLengthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NumSuggestionsUtf8, out IJsonDocument? _, out int _)) + { + SetNumSuggestions(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.NumberOfSuggestionsToMake.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PnpFilesUtf8, out IJsonDocument? _, out int _)) + { + SetPnpFiles(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.PnpFilesJsArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuggestionNumChangesUtf8, out IJsonDocument? _, out int _)) + { + SetSuggestionNumChanges(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.SuggestionNumChangesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuggestionsTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetSuggestionsTimeout(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.SuggestionsTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UsePnPUtf8, out IJsonDocument? _, out int _)) + { + SetUsePnP(Corvus.CspellBenchmark.Current.CspellSchema.OverrideSettings.UsePnPEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NoSuggestDictionariArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NoSuggestDictionariArray.cs index e6e41da0090..cf1e45e333a 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NoSuggestDictionariArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NoSuggestDictionariArray.cs @@ -31,11 +31,13 @@ public readonly partial struct OverrideSettings public readonly partial struct NoSuggestDictionariArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public NoSuggestDictionariArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NumberOfSuggestionsToMake.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NumberOfSuggestionsToMake.cs index 18cc3771975..4ad962e906f 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NumberOfSuggestionsToMake.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.NumberOfSuggestionsToMake.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public NumberOfSuggestionsToMake Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.PnpFilesJsArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.PnpFilesJsArray.cs index 4af4bf5fe2b..c6f1c6d4fe1 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.PnpFilesJsArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.PnpFilesJsArray.cs @@ -39,11 +39,13 @@ public readonly partial struct OverrideSettings public readonly partial struct PnpFilesJsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public PnpFilesJsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.RegExpPatternDefinitionArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.RegExpPatternDefinitionArray.cs index 708ffe88771..a2612e7817f 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.RegExpPatternDefinitionArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.RegExpPatternDefinitionArray.cs @@ -34,11 +34,13 @@ public readonly partial struct OverrideSettings public readonly partial struct RegExpPatternDefinitionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public RegExpPatternDefinitionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestWorArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestWorArray.cs index 944fa8ceb48..7e50ecaea91 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestWorArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestWorArray.cs @@ -37,11 +37,13 @@ public readonly partial struct OverrideSettings public readonly partial struct SuggestWorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public SuggestWorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionNumChangesEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionNumChangesEntity.cs index c5acd180e08..d4e270bb3e7 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionNumChangesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionNumChangesEntity.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public SuggestionNumChangesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionsTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionsTimeoutEntity.cs index 848351ecd53..c14234402f1 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionsTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.SuggestionsTimeoutEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public SuggestionsTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.TheMaximumNumberOfProblemsToReportInAFile.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.TheMaximumNumberOfProblemsToReportInAFile.cs index 98f0358479b..0c45cfa4cad 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.TheMaximumNumberOfProblemsToReportInAFile.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.TheMaximumNumberOfProblemsToReportInAFile.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public TheMaximumNumberOfProblemsToReportInAFile Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.UsePnPEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.UsePnPEntity.cs index 6006a38bdb8..0c55c2d991d 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.UsePnPEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.UsePnPEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public UsePnPEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.cs index 9884eee6c6e..e761a4f9979 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettings.cs @@ -1029,6 +1029,12 @@ private void CheckValidInstance() public OverrideSettings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettingsArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettingsArray.cs index 3bd0ef88ff2..8e605fad64e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettingsArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.OverrideSettingsArray.cs @@ -32,11 +32,13 @@ public readonly partial struct CspellSchema public readonly partial struct OverrideSettingsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public OverrideSettingsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.Mutable.cs index 6c831a975ba..8730e943f65 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.Mutable.cs @@ -304,6 +304,31 @@ public void SetRegexp(scoped in Corvus.CspellBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.cs index 075aa6f7c97..ea0d15cc1bc 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternAdjustment.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public PatternAdjustment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternRef.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternRef.cs index dd17cb64f57..dfae0e125c0 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternRef.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PatternRef.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public PatternRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PnpFilesJsArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PnpFilesJsArray.cs index c8814973df2..c0441bcb3dd 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PnpFilesJsArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PnpFilesJsArray.cs @@ -37,11 +37,13 @@ public readonly partial struct CspellSchema public readonly partial struct PnpFilesJsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -92,6 +94,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -305,6 +322,12 @@ private void CheckValidInstance() public PnpFilesJsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PredefinedPatterns.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PredefinedPatterns.cs index a014e9f3682..e21b7a04537 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PredefinedPatterns.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.PredefinedPatterns.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public PredefinedPatterns Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReadonlyEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReadonlyEntity.cs index d552538a2f6..4b89dd0efbf 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReadonlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReadonlyEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ReadonlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.Mutable.cs index ed609f2af22..06c64dc9e50 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.Mutable.cs @@ -352,6 +352,31 @@ public void SetPattern(in Corvus.CspellBenchmark.Current.CspellSchema. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.JsonStringArray.cs index ea4a44fca5c..db090e2fcc0 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.JsonStringArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RegExpPatternOrArrayOfRegExpPatterns public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.cs index b5558f924e8..4ea65769ef4 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.RegExpPatternOrArrayOfRegExpPatterns.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public RegExpPatternOrArrayOfRegExpPatterns Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.cs index 7b0c8690f6f..16f6b37b8fe 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinition.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public RegExpPatternDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinitionArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinitionArray.cs index 272d8a1de2c..97b5f7cd59b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinitionArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternDefinitionArray.cs @@ -32,11 +32,13 @@ public readonly partial struct CspellSchema public readonly partial struct RegExpPatternDefinitionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public RegExpPatternDefinitionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternList.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternList.cs index fd16417f06a..60690e9e97c 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternList.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.RegExpPatternList.cs @@ -26,11 +26,13 @@ public readonly partial struct CspellSchema public readonly partial struct RegExpPatternList #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RegExpPatternList Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceEntry.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceEntry.cs index 6bde5fc4151..d79247033e3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceEntry.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceEntry.cs @@ -21,11 +21,13 @@ public readonly partial struct CspellSchema public readonly partial struct ReplaceEntry #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public ReplaceEntry Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceMap.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceMap.cs index e0978344de3..757bc026221 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceMap.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReplaceMap.cs @@ -21,11 +21,13 @@ public readonly partial struct CspellSchema public readonly partial struct ReplaceMap #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public ReplaceMap Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.AnyOf2Array.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.AnyOf2Array.cs index 84812adfbac..19deb8cb76c 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.AnyOf2Array.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.AnyOf2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct ReporterSettings public readonly partial struct AnyOf2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public AnyOf2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.JsonStringArray.cs index 46ef206f089..9abff716f20 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ReporterSettings public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -92,6 +94,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -305,6 +322,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.cs index 29ed5438cdc..d7667c4ada5 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettings.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public ReporterSettings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettingsArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettingsArray.cs index e61fd9f5dd3..b58496c8a07 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettingsArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.ReporterSettingsArray.cs @@ -51,11 +51,13 @@ public readonly partial struct CspellSchema public readonly partial struct ReporterSettingsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -106,6 +108,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -319,6 +336,12 @@ private void CheckValidInstance() public ReporterSettingsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Serializable.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Serializable.cs index c217662e279..8afeefce8f7 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Serializable.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Serializable.cs @@ -573,6 +573,12 @@ private void CheckValidInstance() public Serializable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestWorArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestWorArray.cs index 4a43988eafa..dbbc69f5ce2 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestWorArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestWorArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CspellSchema public readonly partial struct SuggestWorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public SuggestWorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostMapDef.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostMapDef.cs index df6d828593a..91bcefdff38 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostMapDef.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostMapDef.cs @@ -440,6 +440,12 @@ private void CheckValidInstance() public SuggestionCostMapDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostsDefs.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostsDefs.cs index 50a8a002c41..3b703eea006 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostsDefs.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionCostsDefs.cs @@ -21,11 +21,13 @@ public readonly partial struct CspellSchema public readonly partial struct SuggestionCostsDefs #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public SuggestionCostsDefs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionNumChangesEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionNumChangesEntity.cs index efabbe83ee4..7275aadedbf 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionNumChangesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionNumChangesEntity.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public SuggestionNumChangesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionsTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionsTimeoutEntity.cs index bc2497319db..8f372b464e3 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionsTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.SuggestionsTimeoutEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public SuggestionsTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.TheMaximumNumberOfProblemsToReportInAFile.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.TheMaximumNumberOfProblemsToReportInAFile.cs index ec23557884c..0a645e8744c 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.TheMaximumNumberOfProblemsToReportInAFile.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.TheMaximumNumberOfProblemsToReportInAFile.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public TheMaximumNumberOfProblemsToReportInAFile Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UrlToJsonSchema.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UrlToJsonSchema.cs index 684926fb520..3e7b1a989b8 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UrlToJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UrlToJsonSchema.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public UrlToJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UseGitignoreEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UseGitignoreEntity.cs index 1d602d3c676..8a535c50882 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UseGitignoreEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UseGitignoreEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public UseGitignoreEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UsePnPEntity.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UsePnPEntity.cs index ffaecaa11d7..0fa53e21542 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UsePnPEntity.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UsePnPEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public UsePnPEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UserWordsJArray.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UserWordsJArray.cs index f173d15bb82..27c5c3a0fe5 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UserWordsJArray.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.UserWordsJArray.cs @@ -26,11 +26,13 @@ public readonly partial struct CspellSchema public readonly partial struct UserWordsJArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public UserWordsJArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Version.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Version.cs index 7053e8d8300..9f4ebec4d3d 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Version.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.Version.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public Version Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLatest.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLatest.cs index fd55b1a4aaa..fa31f569d16 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLatest.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLatest.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public VersionLatest Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLegacy.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLegacy.cs index 65fb9c77e29..f9da496a550 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLegacy.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.VersionLegacy.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public VersionLegacy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.cs index 8a89ef6dfa8..bbdae1ab3e0 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/CspellSchema.cs @@ -1485,6 +1485,12 @@ private void CheckValidInstance() public CspellSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonBoolean.cs index e15b8ce96ba..a7162f868c9 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonBoolean.cs @@ -306,6 +306,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNull.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNull.cs index f53eaaff744..9338fe1ea3b 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNull.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNull.cs @@ -256,6 +256,12 @@ private void CheckValidInstance() public JsonNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNumber.cs index 3915c84a9a1..4f07671bad6 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonNumber.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonObject.cs index ac92f199d50..3df22c6aba7 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonString.cs index ee8fda87cd7..a5e71e7de08 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/corvusjson-jsonschema.lock index 896563febcc..0d64b2f575e 100644 --- a/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.CspellBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:21.4944024\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:56.8894459\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.Mutable.cs index 3aaf05c9105..661ce71db8f 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.Mutable.cs @@ -416,6 +416,43 @@ public bool RemoveE2e() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentUtf8, out Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.Mutable __corvusComponent)) + { + __corvusComponent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.E2eUtf8, out Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.Mutable __corvusE2e)) + { + __corvusE2e.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.cs index 3a40477a659..3d2f15a9e3e 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.AllOf1Entity.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.AnimationDistanceThresholdEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.AnimationDistanceThresholdEntity.cs index 603d3a732b5..27dd3ef075a 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.AnimationDistanceThresholdEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.AnimationDistanceThresholdEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public AnimationDistanceThresholdEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BaseUrlEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BaseUrlEntity.cs index e6d7e7a3742..9c5c6fe4449 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BaseUrlEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BaseUrlEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public BaseUrlEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BlockHostsArray.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BlockHostsArray.cs index c6ba3172b30..40a7e6ec5f7 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BlockHostsArray.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.BlockHostsArray.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public BlockHostsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ChromeWebSecurityEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ChromeWebSecurityEntity.cs index 2910f9145b6..2f762f502f0 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ChromeWebSecurityEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ChromeWebSecurityEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ChromeWebSecurityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ComponentFolderEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ComponentFolderEntity.cs index c886322b7c8..775bf39acac 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ComponentFolderEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ComponentFolderEntity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public ComponentFolderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.DefaultCommandTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.DefaultCommandTimeoutEntity.cs index c4f8a8c8ccf..69923a22566 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.DefaultCommandTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.DefaultCommandTimeoutEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public DefaultCommandTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExecTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExecTimeoutEntity.cs index 44bb1d17808..be2c057d47a 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExecTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExecTimeoutEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ExecTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalInteractiveRunEventsEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalInteractiveRunEventsEntity.cs index 9700686ee70..a71a6178de8 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalInteractiveRunEventsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalInteractiveRunEventsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ExperimentalInteractiveRunEventsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSessionSupportEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSessionSupportEntity.cs index 077932967e6..eb8e165fd10 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSessionSupportEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSessionSupportEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ExperimentalSessionSupportEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSourceRewritingEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSourceRewritingEntity.cs index 46c15e15005..34c2de03ead 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSourceRewritingEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalSourceRewritingEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ExperimentalSourceRewritingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalStudioEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalStudioEntity.cs index 81ae8ad8239..535ed4bfb6f 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalStudioEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ExperimentalStudioEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ExperimentalStudioEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.FileServerFolderEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.FileServerFolderEntity.cs index 905b956f809..d45eedbed46 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.FileServerFolderEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.FileServerFolderEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public FileServerFolderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IgnoreTestFilesArray.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IgnoreTestFilesArray.cs index 528ec4d1681..027f3170cf8 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IgnoreTestFilesArray.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IgnoreTestFilesArray.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public IgnoreTestFilesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IncludeShadowDomEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IncludeShadowDomEntity.cs index c33bd224a94..c0619525252 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IncludeShadowDomEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.IncludeShadowDomEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IncludeShadowDomEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ModifyObstructiveCodeEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ModifyObstructiveCodeEntity.cs index fdcdb8574fc..200ce01c70d 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ModifyObstructiveCodeEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ModifyObstructiveCodeEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ModifyObstructiveCodeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.Mutable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.Mutable.cs index 529e8683528..075897c2244 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.Mutable.cs @@ -3698,6 +3698,261 @@ public bool RemoveWatchForFileChanges() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AnimationDistanceThresholdUtf8, out IJsonDocument? _, out int _)) + { + SetAnimationDistanceThreshold(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.AnimationDistanceThresholdEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BaseUrlUtf8, out IJsonDocument? _, out int _)) + { + SetBaseUrl(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.BaseUrlEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BlockHostsUtf8, out IJsonDocument? _, out int _)) + { + SetBlockHosts(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.BlockHostsArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ChromeWebSecurityUtf8, out IJsonDocument? _, out int _)) + { + SetChromeWebSecurity(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ChromeWebSecurityEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentFolderUtf8, out IJsonDocument? _, out int _)) + { + SetComponentFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ComponentFolderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultCommandTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetDefaultCommandTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.DefaultCommandTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DownloadsFolderUtf8, out IJsonDocument? _, out int _)) + { + SetDownloadsFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderWhereFilesDownloadedDuringATestAreSaved.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExecTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetExecTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExecTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalFetchPolyfillUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalFetchPolyfill(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PolyfillsWindowFetchToEnableNetworkSpyingAndStubbing.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalInteractiveRunEventsUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalInteractiveRunEvents(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalInteractiveRunEventsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalSessionSupportUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalSessionSupport(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalSessionSupportEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalSourceRewritingUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalSourceRewriting(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalSourceRewritingEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalStudioUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalStudio(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalStudioEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FileServerFolderUtf8, out IJsonDocument? _, out int _)) + { + SetFileServerFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.FileServerFolderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FixturesFolderUtf8, out IJsonDocument? _, out int _)) + { + SetFixturesFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderContainingFixtureFilesPassFalseToDisable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IncludeShadowDomUtf8, out IJsonDocument? _, out int _)) + { + SetIncludeShadowDom(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.IncludeShadowDomEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IntegrationFolderUtf8, out IJsonDocument? _, out int _)) + { + SetIntegrationFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderContainingIntegrationTestFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifyObstructiveCodeUtf8, out IJsonDocument? _, out int _)) + { + SetModifyObstructiveCode(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ModifyObstructiveCodeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NodeVersionUtf8, out IJsonDocument? _, out int _)) + { + SetNodeVersion(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.NodeVersionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NumTestsKeptInMemoryUtf8, out IJsonDocument? _, out int _)) + { + SetNumTestsKeptInMemory(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.NumTestsKeptInMemoryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PageLoadTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetPageLoadTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PageLoadTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginsFileUtf8, out IJsonDocument? _, out int _)) + { + SetPluginsFile(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToPluginsFilePassFalseToDisable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PortUtf8, out IJsonDocument? _, out int _)) + { + SetPort(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PortEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProjectIdUtf8, out IJsonDocument? _, out int _)) + { + SetProjectId(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ProjectIdEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReporterUtf8, out IJsonDocument? _, out int _)) + { + SetReporter(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ReporterEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReporterOptionsUtf8, out IJsonDocument? _, out int _)) + { + SetReporterOptions(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ReporterOptionsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequestTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetRequestTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.RequestTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResponseTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetResponseTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ResponseTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RetriesUtf8, out IJsonDocument? _, out int _)) + { + SetRetries(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.RetriesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScreenshotOnRunFailureUtf8, out IJsonDocument? _, out int _)) + { + SetScreenshotOnRunFailure(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ScreenshotOnRunFailureEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScreenshotsFolderUtf8, out IJsonDocument? _, out int _)) + { + SetScreenshotsFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ScreenshotsFolderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScrollBehaviorUtf8, out IJsonDocument? _, out int _)) + { + SetScrollBehavior(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ScrollBehaviorEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SlowTestThresholdUtf8, out IJsonDocument? _, out int _)) + { + SetSlowTestThreshold(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.SlowTestThresholdEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SupportFileUtf8, out IJsonDocument? _, out int _)) + { + SetSupportFile(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.SupportFileEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetTaskTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.TaskTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TestFilesUtf8, out IJsonDocument? _, out int _)) + { + SetTestFiles(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.TestFilesArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TrashAssetsBeforeRunsUtf8, out IJsonDocument? _, out int _)) + { + SetTrashAssetsBeforeRuns(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.TrashAssetsBeforeRunsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UserAgentUtf8, out IJsonDocument? _, out int _)) + { + SetUserAgent(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.UserAgentEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideoUtf8, out IJsonDocument? _, out int _)) + { + SetVideo(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.VideoEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideoCompressionUtf8, out IJsonDocument? _, out int _)) + { + SetVideoCompression(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.VideoCompressionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideoUploadOnPassesUtf8, out IJsonDocument? _, out int _)) + { + SetVideoUploadOnPasses(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.VideoUploadOnPassesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideosFolderUtf8, out IJsonDocument? _, out int _)) + { + SetVideosFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderWhereVideosWillBeSavedDuringCypressRun.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ViewportHeightUtf8, out IJsonDocument? _, out int _)) + { + SetViewportHeight(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ViewportHeightEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ViewportWidthUtf8, out IJsonDocument? _, out int _)) + { + SetViewportWidth(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ViewportWidthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WaitForAnimationsUtf8, out IJsonDocument? _, out int _)) + { + SetWaitForAnimations(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.WaitForAnimationsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchForFileChangesUtf8, out IJsonDocument? _, out int _)) + { + SetWatchForFileChanges(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.WatchForFileChangesEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NodeVersionEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NodeVersionEntity.cs index b7fb528ab37..0344fc466b1 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NodeVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NodeVersionEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public NodeVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NumTestsKeptInMemoryEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NumTestsKeptInMemoryEntity.cs index 2ebd25ee286..68bf73c3078 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NumTestsKeptInMemoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.NumTestsKeptInMemoryEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public NumTestsKeptInMemoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PageLoadTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PageLoadTimeoutEntity.cs index 806c5b0f57d..63ed3040760 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PageLoadTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PageLoadTimeoutEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public PageLoadTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingFixtureFilesPassFalseToDisable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingFixtureFilesPassFalseToDisable.cs index c658f8e3ced..a6537255020 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingFixtureFilesPassFalseToDisable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingFixtureFilesPassFalseToDisable.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public PathToFolderContainingFixtureFilesPassFalseToDisable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingIntegrationTestFiles.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingIntegrationTestFiles.cs index 4f1d3c7a6bc..5fb05f8a4e3 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingIntegrationTestFiles.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderContainingIntegrationTestFiles.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public PathToFolderContainingIntegrationTestFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereFilesDownloadedDuringATestAreSaved.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereFilesDownloadedDuringATestAreSaved.cs index ebe1e353282..6a6ee061bcd 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereFilesDownloadedDuringATestAreSaved.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereFilesDownloadedDuringATestAreSaved.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public PathToFolderWhereFilesDownloadedDuringATestAreSaved Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereVideosWillBeSavedDuringCypressRun.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereVideosWillBeSavedDuringCypressRun.cs index 82b23203427..b8ddb905ef5 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereVideosWillBeSavedDuringCypressRun.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToFolderWhereVideosWillBeSavedDuringCypressRun.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public PathToFolderWhereVideosWillBeSavedDuringCypressRun Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToPluginsFilePassFalseToDisable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToPluginsFilePassFalseToDisable.cs index 7427ddf6b3f..3769d707472 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToPluginsFilePassFalseToDisable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PathToPluginsFilePassFalseToDisable.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public PathToPluginsFilePassFalseToDisable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PolyfillsWindowFetchToEnableNetworkSpyingAndStubbing.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PolyfillsWindowFetchToEnableNetworkSpyingAndStubbing.cs index 69e14605f08..42e09881dac 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PolyfillsWindowFetchToEnableNetworkSpyingAndStubbing.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PolyfillsWindowFetchToEnableNetworkSpyingAndStubbing.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public PolyfillsWindowFetchToEnableNetworkSpyingAndStubbing Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PortEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PortEntity.cs index f7f6f4bd4b9..68b3c40141b 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PortEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.PortEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public PortEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ProjectIdEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ProjectIdEntity.cs index b1c563816fd..a5fc53b8a27 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ProjectIdEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ProjectIdEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ProjectIdEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterEntity.cs index c31fb6312d9..f6ac2c148db 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ReporterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterOptionsEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterOptionsEntity.cs index aef6996125b..cd46a112434 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ReporterOptionsEntity.cs @@ -354,6 +354,12 @@ private void CheckValidInstance() public ReporterOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequestTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequestTimeoutEntity.cs index 825eb1f074c..6c20b1a741f 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequestTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequestTimeoutEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public RequestTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.Mutable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.Mutable.cs index e974becef58..600b51371c1 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.Mutable.cs @@ -398,6 +398,31 @@ public bool RemovePassphrase() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.cs index 5f4a4601876..9288a75353c 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PemFileSpecificProperties.cs @@ -423,6 +423,12 @@ private void CheckValidInstance() public PemFileSpecificProperties Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.Mutable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.Mutable.cs index 2b1e8ba911c..fa899031e8c 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.Mutable.cs @@ -343,6 +343,31 @@ public void SetPfx(scoped in Corvus.CypressBenchmark.Current.JsonString.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.cs index d3fd6fefc59..e23c8c76a61 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.PfxFileSpecificProperties.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public PfxFileSpecificProperties Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.cs index 3afd884932d..7701b55b1e9 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.CertsEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public CertsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.cs index 0c102ce8172..7852a346a2d 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.CertsEntityArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredCertsAndUrl public readonly partial struct CertsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public CertsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.JsonStringArray.cs index 6b63e7d7acf..8a0063070f0 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.JsonStringArray.cs @@ -32,11 +32,13 @@ public readonly partial struct RequiredCertsAndUrl public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.Mutable.cs index 7963c007acc..f1ad35f571c 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.Mutable.cs @@ -459,6 +459,31 @@ public void SetUrl(scoped in Corvus.CypressBenchmark.Current.JsonString.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.cs index c09761b9e0a..9d8fdaa3e8e 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.RequiredCertsAndUrl.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public RequiredCertsAndUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.cs index 1457c349462..5d9b518544c 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RequiredCertsAndUrlArray.cs @@ -28,11 +28,13 @@ public readonly partial struct CypressConfig public readonly partial struct RequiredCertsAndUrlArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public RequiredCertsAndUrlArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ResponseTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ResponseTimeoutEntity.cs index 041b901093a..9c97b942fcf 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ResponseTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ResponseTimeoutEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ResponseTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RetriesEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RetriesEntity.cs index 0761b786c4f..39d98aee41b 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RetriesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.RetriesEntity.cs @@ -496,6 +496,12 @@ private void CheckValidInstance() public RetriesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotOnRunFailureEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotOnRunFailureEntity.cs index d36e97da30a..c5345a2191c 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotOnRunFailureEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotOnRunFailureEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ScreenshotOnRunFailureEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotsFolderEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotsFolderEntity.cs index 3c05c7226c6..26d8c75c782 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotsFolderEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScreenshotsFolderEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ScreenshotsFolderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScrollBehaviorEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScrollBehaviorEntity.cs index 4cf3e0aac53..1e01d885df2 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScrollBehaviorEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ScrollBehaviorEntity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public ScrollBehaviorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SlowTestThresholdEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SlowTestThresholdEntity.cs index e51df9f818c..e4ce1ccbc77 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SlowTestThresholdEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SlowTestThresholdEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public SlowTestThresholdEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SupportFileEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SupportFileEntity.cs index aae3917827e..127dffbeae4 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SupportFileEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.SupportFileEntity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public SupportFileEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TaskTimeoutEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TaskTimeoutEntity.cs index 7643fd9e317..8614a294c6e 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TaskTimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TaskTimeoutEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public TaskTimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TestFilesArray.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TestFilesArray.cs index 39b22edce7e..8a26a6b7cbe 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TestFilesArray.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TestFilesArray.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public TestFilesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TrashAssetsBeforeRunsEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TrashAssetsBeforeRunsEntity.cs index 2d0d7c130d1..a2663b70f90 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TrashAssetsBeforeRunsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.TrashAssetsBeforeRunsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public TrashAssetsBeforeRunsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.UserAgentEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.UserAgentEntity.cs index 3d6c87fdbca..12e4ad10ada 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.UserAgentEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.UserAgentEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public UserAgentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoCompressionEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoCompressionEntity.cs index 61535315cf5..9cff78f8dc9 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoCompressionEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoCompressionEntity.cs @@ -454,6 +454,12 @@ private void CheckValidInstance() public VideoCompressionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoEntity.cs index d141203c090..11541e05ffc 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public VideoEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoUploadOnPassesEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoUploadOnPassesEntity.cs index 7e88b5f30a6..04b2c2d9e11 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoUploadOnPassesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.VideoUploadOnPassesEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public VideoUploadOnPassesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportHeightEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportHeightEntity.cs index 87514a94efc..85d6824c2a7 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportHeightEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportHeightEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ViewportHeightEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportWidthEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportWidthEntity.cs index 9b985c8d7ab..89df664c5a5 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.ViewportWidthEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ViewportWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WaitForAnimationsEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WaitForAnimationsEntity.cs index 4a07d4862db..ba6455d4d06 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WaitForAnimationsEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WaitForAnimationsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WaitForAnimationsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WatchForFileChangesEntity.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WatchForFileChangesEntity.cs index afd2e2041fc..aa5a75997f6 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WatchForFileChangesEntity.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.WatchForFileChangesEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WatchForFileChangesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.cs index 0cb11c0ab11..e7a2658f3dd 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.CypressConfig.cs @@ -1368,6 +1368,12 @@ private void CheckValidInstance() public CypressConfig Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.Mutable.cs index 4f8ad6ccb38..d45e3174eeb 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.Mutable.cs @@ -3935,6 +3935,273 @@ public bool RemoveWatchForFileChanges() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AnimationDistanceThresholdUtf8, out IJsonDocument? _, out int _)) + { + SetAnimationDistanceThreshold(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.AnimationDistanceThresholdEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BaseUrlUtf8, out IJsonDocument? _, out int _)) + { + SetBaseUrl(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.BaseUrlEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BlockHostsUtf8, out IJsonDocument? _, out int _)) + { + SetBlockHosts(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.BlockHostsArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ChromeWebSecurityUtf8, out IJsonDocument? _, out int _)) + { + SetChromeWebSecurity(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ChromeWebSecurityEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentFolderUtf8, out IJsonDocument? _, out int _)) + { + SetComponentFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ComponentFolderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultCommandTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetDefaultCommandTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.DefaultCommandTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DownloadsFolderUtf8, out IJsonDocument? _, out int _)) + { + SetDownloadsFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderWhereFilesDownloadedDuringATestAreSaved.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExecTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetExecTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExecTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalFetchPolyfillUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalFetchPolyfill(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PolyfillsWindowFetchToEnableNetworkSpyingAndStubbing.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalInteractiveRunEventsUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalInteractiveRunEvents(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalInteractiveRunEventsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalSessionSupportUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalSessionSupport(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalSessionSupportEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalSourceRewritingUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalSourceRewriting(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalSourceRewritingEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalStudioUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalStudio(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ExperimentalStudioEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FileServerFolderUtf8, out IJsonDocument? _, out int _)) + { + SetFileServerFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.FileServerFolderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FixturesFolderUtf8, out IJsonDocument? _, out int _)) + { + SetFixturesFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderContainingFixtureFilesPassFalseToDisable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IncludeShadowDomUtf8, out IJsonDocument? _, out int _)) + { + SetIncludeShadowDom(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.IncludeShadowDomEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IntegrationFolderUtf8, out IJsonDocument? _, out int _)) + { + SetIntegrationFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderContainingIntegrationTestFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifyObstructiveCodeUtf8, out IJsonDocument? _, out int _)) + { + SetModifyObstructiveCode(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ModifyObstructiveCodeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NodeVersionUtf8, out IJsonDocument? _, out int _)) + { + SetNodeVersion(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.NodeVersionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NumTestsKeptInMemoryUtf8, out IJsonDocument? _, out int _)) + { + SetNumTestsKeptInMemory(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.NumTestsKeptInMemoryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PageLoadTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetPageLoadTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PageLoadTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginsFileUtf8, out IJsonDocument? _, out int _)) + { + SetPluginsFile(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToPluginsFilePassFalseToDisable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PortUtf8, out IJsonDocument? _, out int _)) + { + SetPort(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PortEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProjectIdUtf8, out IJsonDocument? _, out int _)) + { + SetProjectId(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ProjectIdEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReporterUtf8, out IJsonDocument? _, out int _)) + { + SetReporter(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ReporterEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReporterOptionsUtf8, out IJsonDocument? _, out int _)) + { + SetReporterOptions(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ReporterOptionsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequestTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetRequestTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.RequestTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResponseTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetResponseTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ResponseTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RetriesUtf8, out IJsonDocument? _, out int _)) + { + SetRetries(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.RetriesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScreenshotOnRunFailureUtf8, out IJsonDocument? _, out int _)) + { + SetScreenshotOnRunFailure(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ScreenshotOnRunFailureEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScreenshotsFolderUtf8, out IJsonDocument? _, out int _)) + { + SetScreenshotsFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ScreenshotsFolderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScrollBehaviorUtf8, out IJsonDocument? _, out int _)) + { + SetScrollBehavior(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ScrollBehaviorEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SlowTestThresholdUtf8, out IJsonDocument? _, out int _)) + { + SetSlowTestThreshold(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.SlowTestThresholdEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SupportFileUtf8, out IJsonDocument? _, out int _)) + { + SetSupportFile(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.SupportFileEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskTimeoutUtf8, out IJsonDocument? _, out int _)) + { + SetTaskTimeout(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.TaskTimeoutEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TestFilesUtf8, out IJsonDocument? _, out int _)) + { + SetTestFiles(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.TestFilesArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TrashAssetsBeforeRunsUtf8, out IJsonDocument? _, out int _)) + { + SetTrashAssetsBeforeRuns(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.TrashAssetsBeforeRunsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UserAgentUtf8, out IJsonDocument? _, out int _)) + { + SetUserAgent(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.UserAgentEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideoUtf8, out IJsonDocument? _, out int _)) + { + SetVideo(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.VideoEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideoCompressionUtf8, out IJsonDocument? _, out int _)) + { + SetVideoCompression(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.VideoCompressionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideoUploadOnPassesUtf8, out IJsonDocument? _, out int _)) + { + SetVideoUploadOnPasses(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.VideoUploadOnPassesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VideosFolderUtf8, out IJsonDocument? _, out int _)) + { + SetVideosFolder(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.PathToFolderWhereVideosWillBeSavedDuringCypressRun.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ViewportHeightUtf8, out IJsonDocument? _, out int _)) + { + SetViewportHeight(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ViewportHeightEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ViewportWidthUtf8, out IJsonDocument? _, out int _)) + { + SetViewportWidth(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.ViewportWidthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WaitForAnimationsUtf8, out IJsonDocument? _, out int _)) + { + SetWaitForAnimations(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.WaitForAnimationsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchForFileChangesUtf8, out IJsonDocument? _, out int _)) + { + SetWatchForFileChanges(Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.WatchForFileChangesEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentUtf8, out Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.Mutable __corvusComponent)) + { + __corvusComponent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.E2eUtf8, out Corvus.CypressBenchmark.Current.CypressSchema.CypressConfig.Mutable __corvusE2e)) + { + __corvusE2e.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.cs index 98ac5be2564..2f603665d45 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/CypressSchema.cs @@ -1443,6 +1443,12 @@ private void CheckValidInstance() public CypressSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonObject.cs index 3447ec82e45..db01b0d8cde 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonString.cs index fb3e1a4cdb8..06d72cd53ac 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/corvusjson-jsonschema.lock index 024a86fff47..701ef84b714 100644 --- a/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.CypressBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:24.3568877\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:58.5042964\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.AMapOfSpecifiersToTheirRemappedSpecifiers.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.AMapOfSpecifiersToTheirRemappedSpecifiers.cs index ee832dcf9f3..890886a0195 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.AMapOfSpecifiersToTheirRemappedSpecifiers.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.AMapOfSpecifiersToTheirRemappedSpecifiers.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public AMapOfSpecifiersToTheirRemappedSpecifiers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.IncludeJsoArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.IncludeJsoArray.cs index b0bb749fbc7..f6f0df56772 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.IncludeJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.IncludeJsoArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct IncludeJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public IncludeJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.JsonStringArray.cs index 2724f45c1eb..1cc15c267c5 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.Mutable.cs index 65da44ffa7b..55e9bc6bcb7 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.Mutable.cs @@ -418,6 +418,31 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.cs index 23ff437fc7b..26df57a19ed 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.FilesEntity.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public FilesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.IncludeJsoArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.IncludeJsoArray.cs index d20cc8a9663..74822252334 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.IncludeJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.IncludeJsoArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForDenoBench public readonly partial struct IncludeJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public IncludeJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.JsonStringArray.cs index 102c85f7188..628e83256e3 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForDenoBench public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.Mutable.cs index e6066cf979e..590d4000411 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.Mutable.cs @@ -513,6 +513,37 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilesUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForDenoBench.FilesEntity.Mutable __corvusFiles)) + { + __corvusFiles.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.cs index f1806f26da5..448036bf964 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoBench.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ConfigurationForDenoBench Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTask.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTask.cs index b9f50fb7d7f..3c1c125c00c 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTask.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTask.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public ConfigurationForDenoTask Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.IncludeJsoArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.IncludeJsoArray.cs index 4ba69f342e3..4de83c37a03 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.IncludeJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.IncludeJsoArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct IncludeJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public IncludeJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.JsonStringArray.cs index 9e6d5a6a4a2..5d28a8de477 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.Mutable.cs index cb1f3f4b062..4100de34f83 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.Mutable.cs @@ -418,6 +418,31 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.cs index d12b0bd10de..4baf49a5ac2 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.FilesEntity.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public FilesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.IncludeJsoArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.IncludeJsoArray.cs index 2c92d549b16..1fe2a4d1aff 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.IncludeJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.IncludeJsoArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForDenoTest public readonly partial struct IncludeJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public IncludeJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.JsonStringArray.cs index 1fc258977f5..64c6d9315b7 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForDenoTest public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.Mutable.cs index 9d9ecc5e4dd..2de846bed35 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.Mutable.cs @@ -513,6 +513,37 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilesUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForDenoTest.FilesEntity.Mutable __corvusFiles)) + { + __corvusFiles.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.cs index f5eb5ae602d..dba19fb2c5f 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForDenoTest.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public ConfigurationForDenoTest Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.DefineHowProseShouldBeWrappedInMarkdownFiles.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.DefineHowProseShouldBeWrappedInMarkdownFiles.cs index 121033f2d77..f42d629b4cf 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.DefineHowProseShouldBeWrappedInMarkdownFiles.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.DefineHowProseShouldBeWrappedInMarkdownFiles.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public DefineHowProseShouldBeWrappedInMarkdownFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.JsonStringArray.cs index 0418a31b643..cd2579d9075 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.ListOfFileArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.ListOfFileArray.cs index 7c7d0a8c91a..1eca837e730 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.ListOfFileArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.ListOfFileArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct ListOfFileArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ListOfFileArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.Mutable.cs index 6c5a5c7883a..ec92e7423c7 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.Mutable.cs @@ -418,6 +418,31 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.cs index b902bed470e..9ea6f5fad67 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.FilesEntity.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public FilesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.JsonStringArray.cs index 590635d492f..e79e3dca80a 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForFormatter public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.LineWidthEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.LineWidthEntity.cs index eac7a36bd2b..b016c39202e 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.LineWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.LineWidthEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public LineWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.ListOfFileArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.ListOfFileArray.cs index af53a7229e4..577a6fedaa4 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.ListOfFileArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.ListOfFileArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForFormatter public readonly partial struct ListOfFileArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfFileArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.Mutable.cs index c2bddf7611f..07f0a3b09a5 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.Mutable.cs @@ -1006,6 +1006,73 @@ public bool RemoveUseTabs() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentWidthUtf8, out IJsonDocument? _, out int _)) + { + SetIndentWidth(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.TheNumberOfCharactersForAnIndent.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LineWidthUtf8, out IJsonDocument? _, out int _)) + { + SetLineWidth(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.LineWidthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProseWrapUtf8, out IJsonDocument? _, out int _)) + { + SetProseWrap(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.DefineHowProseShouldBeWrappedInMarkdownFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SemiColonsUtf8, out IJsonDocument? _, out int _)) + { + SetSemiColons(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.WhetherToPreferUsingSemicolons.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SingleQuoteUtf8, out IJsonDocument? _, out int _)) + { + SetSingleQuote(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.SingleQuoteEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseTabsUtf8, out IJsonDocument? _, out int _)) + { + SetUseTabs(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.WhetherToUseTabsTrueOrSpacesFalseForIndentation.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilesUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.FilesEntity.Mutable __corvusFiles)) + { + __corvusFiles.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionsUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.OptionsEntity.Mutable __corvusOptions)) + { + __corvusOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.DefineHowProseShouldBeWrappedInMarkdownFiles.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.DefineHowProseShouldBeWrappedInMarkdownFiles.cs index 14a0e065915..ab00d475ed3 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.DefineHowProseShouldBeWrappedInMarkdownFiles.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.DefineHowProseShouldBeWrappedInMarkdownFiles.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public DefineHowProseShouldBeWrappedInMarkdownFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.LineWidthEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.LineWidthEntity.cs index bd46cfc4a5d..50cb74dfe9e 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.LineWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.LineWidthEntity.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public LineWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.Mutable.cs index 9ef51d9a381..b882434697a 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.Mutable.cs @@ -610,6 +610,61 @@ public bool RemoveUseTabs() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentWidthUtf8, out IJsonDocument? _, out int _)) + { + SetIndentWidth(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.OptionsEntity.TheNumberOfCharactersForAnIndent.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LineWidthUtf8, out IJsonDocument? _, out int _)) + { + SetLineWidth(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.OptionsEntity.LineWidthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProseWrapUtf8, out IJsonDocument? _, out int _)) + { + SetProseWrap(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.OptionsEntity.DefineHowProseShouldBeWrappedInMarkdownFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SemiColonsUtf8, out IJsonDocument? _, out int _)) + { + SetSemiColons(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToPreferUsingSemicolons.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SingleQuoteUtf8, out IJsonDocument? _, out int _)) + { + SetSingleQuote(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.OptionsEntity.SingleQuoteEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseTabsUtf8, out IJsonDocument? _, out int _)) + { + SetUseTabs(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToUseTabsTrueOrSpacesFalseForIndentation.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.SingleQuoteEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.SingleQuoteEntity.cs index cd0df00781f..4fc809a6f30 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.SingleQuoteEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.SingleQuoteEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SingleQuoteEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.TheNumberOfCharactersForAnIndent.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.TheNumberOfCharactersForAnIndent.cs index 53a3435bfd7..93ca8762e3d 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.TheNumberOfCharactersForAnIndent.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.TheNumberOfCharactersForAnIndent.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public TheNumberOfCharactersForAnIndent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToPreferUsingSemicolons.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToPreferUsingSemicolons.cs index ccc4aec7b1a..abb8b7b9881 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToPreferUsingSemicolons.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToPreferUsingSemicolons.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WhetherToPreferUsingSemicolons Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs index 270d58257c9..c00b2f7a9a5 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WhetherToUseTabsTrueOrSpacesFalseForIndentation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.cs index 67e2d26fc9b..15ed87b7219 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.OptionsEntity.cs @@ -467,6 +467,12 @@ private void CheckValidInstance() public OptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.SingleQuoteEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.SingleQuoteEntity.cs index 46983cc9689..178cc984b39 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.SingleQuoteEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.SingleQuoteEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public SingleQuoteEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.TheNumberOfCharactersForAnIndent.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.TheNumberOfCharactersForAnIndent.cs index 75e2e7e34d6..ba3f9014c10 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.TheNumberOfCharactersForAnIndent.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.TheNumberOfCharactersForAnIndent.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public TheNumberOfCharactersForAnIndent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToPreferUsingSemicolons.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToPreferUsingSemicolons.cs index 8b2b6ba449c..69c4f66a28e 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToPreferUsingSemicolons.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToPreferUsingSemicolons.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhetherToPreferUsingSemicolons Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs index 6f36d8cb397..8b602a5ed3c 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.WhetherToUseTabsTrueOrSpacesFalseForIndentation.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhetherToUseTabsTrueOrSpacesFalseForIndentation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.cs index 2128abe4164..379def62b0f 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForFormatter.cs @@ -544,6 +544,12 @@ private void CheckValidInstance() public ConfigurationForFormatter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.JsonStringArray.cs index 7a11e26951d..ca380d7491e 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.ListOfFileArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.ListOfFileArray.cs index e767744f169..0dd45ddee36 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.ListOfFileArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.ListOfFileArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FilesEntity public readonly partial struct ListOfFileArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ListOfFileArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.Mutable.cs index eefa836e63b..898b3c4b35d 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.Mutable.cs @@ -418,6 +418,31 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.cs index ed3ea0dbb77..1cc0b0c5892 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.FilesEntity.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public FilesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.JsonStringArray.cs index 2e84d04c88c..427e3d1bed9 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForLinter public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.ListOfFileArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.ListOfFileArray.cs index a4eaffdfa3a..818369e714f 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.ListOfFileArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.ListOfFileArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationForLinter public readonly partial struct ListOfFileArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfFileArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.Mutable.cs index 3eb7c51a4ae..d127f52830d 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.Mutable.cs @@ -676,6 +676,48 @@ public bool RemoveRules() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReportUtf8, out IJsonDocument? _, out int _)) + { + SetReport(Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForLinter.TheDefaultReportFormatToUseWhenLinting.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilesUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForLinter.FilesEntity.Mutable __corvusFiles)) + { + __corvusFiles.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RulesUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForLinter.RulesEntity.Mutable __corvusRules)) + { + __corvusRules.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.IncludeJsoArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.IncludeJsoArray.cs index b3498b917f1..f9c3aaa79be 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.IncludeJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.IncludeJsoArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RulesEntity public readonly partial struct IncludeJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -99,6 +101,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -312,6 +329,12 @@ private void CheckValidInstance() public IncludeJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.JsonStringArray.cs index 623575aaff1..5637b0897c2 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RulesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -99,6 +101,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -312,6 +329,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.Mutable.cs index bbfeff014ad..95ca4123f7f 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.Mutable.cs @@ -520,6 +520,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.TagsJsonStArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.TagsJsonStArray.cs index 570d65cef9c..bd0c12936d2 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.TagsJsonStArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.TagsJsonStArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RulesEntity public readonly partial struct TagsJsonStArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -99,6 +101,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -312,6 +329,12 @@ private void CheckValidInstance() public TagsJsonStArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.cs index d89a80b0687..88b363d2038 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.RulesEntity.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public RulesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.TheDefaultReportFormatToUseWhenLinting.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.TheDefaultReportFormatToUseWhenLinting.cs index 0b7e915a709..cd3289e6320 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.TheDefaultReportFormatToUseWhenLinting.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.TheDefaultReportFormatToUseWhenLinting.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheDefaultReportFormatToUseWhenLinting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.cs index 17d6fe6cdd3..04551155be2 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ConfigurationForLinter.cs @@ -439,6 +439,12 @@ private void CheckValidInstance() public ConfigurationForLinter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AddUndefinedToATypeWhenAccessedUsingAnIndex.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AddUndefinedToATypeWhenAccessedUsingAnIndex.cs index 496d345b6f1..4987d368b91 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AddUndefinedToATypeWhenAccessedUsingAnIndex.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AddUndefinedToATypeWhenAccessedUsingAnIndex.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AddUndefinedToATypeWhenAccessedUsingAnIndex Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs index a9cf18ea862..b682df9f6c7 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AllowJsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnreachableCode.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnreachableCode.cs index a11080df1cf..73d27868b2e 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnreachableCode.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnreachableCode.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DisableErrorReportingForUnreachableCode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnusedLabels.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnusedLabels.cs index 7a4c835f790..5c3c4b110b4 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnusedLabels.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnusedLabels.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DisableErrorReportingForUnusedLabels Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DoNotTruncateErrorMessages.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DoNotTruncateErrorMessages.cs index 48b3a1ddafb..6687bcae3f4 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DoNotTruncateErrorMessages.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DoNotTruncateErrorMessages.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DoNotTruncateErrorMessages Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs index c6b015a6f12..a1d285713c2 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableAllStrictTypeCheckingOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs index ab763dd0bc6..7545e2a7ea0 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableErrorReportingInTypeCheckedJavaScriptFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs index 52b82b6f9e3..d70c11bc1e7 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableErrorReportingWhenALocalVariablesArenTRead Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenThisIsGivenTheTypeAny.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenThisIsGivenTheTypeAny.cs index 8c87227bbea..51c90b68ec6 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenThisIsGivenTheTypeAny.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenThisIsGivenTheTypeAny.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableErrorReportingWhenThisIsGivenTheTypeAny Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableExperimentalSupportForTc39Stage2DraftDecorators.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableExperimentalSupportForTc39Stage2DraftDecorators.cs index b3f20925f77..7eec6797400 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableExperimentalSupportForTc39Stage2DraftDecorators.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableExperimentalSupportForTc39Stage2DraftDecorators.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableExperimentalSupportForTc39Stage2DraftDecorators Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs index d9308ccbe4b..a9c7fa22744 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ExactOptionalPropertyTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs index f9713bcb626..df38ac6d26e 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs @@ -38,11 +38,13 @@ public readonly partial struct InstructsTheTypeScriptCompilerHowToCompileTsFiles public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -93,6 +95,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs index 77413145306..ae11f8826f7 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public JsxFactoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs index 4f97ecc25aa..9749bb48acd 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public JsxFragmentFactoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs index 646749ccda2..ff146c5a9fe 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public JsxImportSourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs index 5da938aa542..44e9481c241 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public KeyofStringsOnlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs index 7bdef73d3ca..b3b736c645b 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs @@ -2228,6 +2228,181 @@ public bool RemoveSuppressImplicitAnyIndexErrors() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowJsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowJs(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowUnreachableCodeUtf8, out IJsonDocument? _, out int _)) + { + SetAllowUnreachableCode(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnreachableCode.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowUnusedLabelsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowUnusedLabels(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErrorReportingForUnusedLabels.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CheckJsUtf8, out IJsonDocument? _, out int _)) + { + SetCheckJs(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExactOptionalPropertyTypesUtf8, out IJsonDocument? _, out int _)) + { + SetExactOptionalPropertyTypes(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExperimentalDecoratorsUtf8, out IJsonDocument? _, out int _)) + { + SetExperimentalDecorators(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableExperimentalSupportForTc39Stage2DraftDecorators.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsxUtf8, out IJsonDocument? _, out int _)) + { + SetJsx(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsxFactoryUtf8, out IJsonDocument? _, out int _)) + { + SetJsxFactory(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsxFragmentFactoryUtf8, out IJsonDocument? _, out int _)) + { + SetJsxFragmentFactory(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsxImportSourceUtf8, out IJsonDocument? _, out int _)) + { + SetJsxImportSource(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.KeyofStringsOnlyUtf8, out IJsonDocument? _, out int _)) + { + SetKeyofStringsOnly(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibUtf8, out IJsonDocument? _, out int _)) + { + SetLib(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoErrorTruncationUtf8, out IJsonDocument? _, out int _)) + { + SetNoErrorTruncation(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DoNotTruncateErrorMessages.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoFallthroughCasesInSwitchUtf8, out IJsonDocument? _, out int _)) + { + SetNoFallthroughCasesInSwitch(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitAnyUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitAny(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitAnyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitOverrideUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitOverride(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitReturnsUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitReturns(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitThisUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitThis(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenThisIsGivenTheTypeAny.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitUseStrictUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitUseStrict(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoStrictGenericChecksUtf8, out IJsonDocument? _, out int _)) + { + SetNoStrictGenericChecks(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoUncheckedIndexedAccessUtf8, out IJsonDocument? _, out int _)) + { + SetNoUncheckedIndexedAccess(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AddUndefinedToATypeWhenAccessedUsingAnIndex.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoUnusedLocalsUtf8, out IJsonDocument? _, out int _)) + { + SetNoUnusedLocals(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoUnusedParametersUtf8, out IJsonDocument? _, out int _)) + { + SetNoUnusedParameters(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictUtf8, out IJsonDocument? _, out int _)) + { + SetStrict(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictBindCallApplyUtf8, out IJsonDocument? _, out int _)) + { + SetStrictBindCallApply(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictFunctionTypesUtf8, out IJsonDocument? _, out int _)) + { + SetStrictFunctionTypes(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictNullChecksUtf8, out IJsonDocument? _, out int _)) + { + SetStrictNullChecks(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictPropertyInitializationUtf8, out IJsonDocument? _, out int _)) + { + SetStrictPropertyInitialization(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuppressExcessPropertyErrorsUtf8, out IJsonDocument? _, out int _)) + { + SetSuppressExcessPropertyErrors(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuppressImplicitAnyIndexErrorsUtf8, out IJsonDocument? _, out int _)) + { + SetSuppressImplicitAnyIndexErrors(Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs index 6a5bcc17e94..b767c4148b8 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public NoFallthroughCasesInSwitchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitAnyEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitAnyEntity.cs index d7fef81d169..afcdbc6bd41 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitAnyEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitAnyEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public NoImplicitAnyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs index ecdf7098cbd..adf2d414eda 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public NoImplicitOverrideEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs index 2a0f988f0cd..788f97ffc9a 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public NoImplicitReturnsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs index 615f0ebb2ce..c45f497a00a 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public NoImplicitUseStrictEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs index 78f5520ed13..3b5535f151b 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public NoStrictGenericChecksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs index 0b12712b40e..80e94025567 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RaiseAnErrorWhenAFunctionParameterIsnTRead Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs index 8b5de2ecc91..9ecfcaff98b 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public SpecifyWhatJsxCodeIsGenerated Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs index 43f7fc53677..a9414e73e03 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public StrictBindCallApplyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs index e7e6dce9c2d..0a670c48f18 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public StrictFunctionTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs index e89a380d454..fedfb4df460 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public StrictPropertyInitializationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs index 07cb1c8b25a..d87c999ac91 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public SuppressExcessPropertyErrorsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs index ae02f789b04..566741926eb 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public SuppressImplicitAnyIndexErrorsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs index c154e4bded4..eccb5befc1e 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhenTypeCheckingTakeIntoAccountNullAndUndefined Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs index 9abb5b6a2de..fc735d8bb15 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs @@ -974,6 +974,12 @@ private void CheckValidInstance() public InstructsTheTypeScriptCompilerHowToCompileTsFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.JsonStringArray.cs index e253d53c2bf..8b89b2ee6f4 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.JsonStringArray.cs @@ -26,11 +26,13 @@ public readonly partial struct DenoSchema public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.LockEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.LockEntity.cs index 9e69b8e3a7e..b160d58fea8 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.LockEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.LockEntity.cs @@ -368,6 +368,12 @@ private void CheckValidInstance() public LockEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.Mutable.cs index b7474678ea2..50ebc72bf45 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.Mutable.cs @@ -1391,6 +1391,71 @@ public bool RemoveVendor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LockUtf8, out IJsonDocument? _, out int _)) + { + SetLock(Corvus.DenoBenchmark.Current.DenoSchema.LockEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScopesUtf8, out IJsonDocument? _, out int _)) + { + SetScopes(Corvus.DenoBenchmark.Current.DenoSchema.ScopesEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BenchUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForDenoBench.Mutable __corvusBench)) + { + __corvusBench.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompilerOptionsUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable __corvusCompilerOptions)) + { + __corvusCompilerOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FmtUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForFormatter.Mutable __corvusFmt)) + { + __corvusFmt.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LintUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForLinter.Mutable __corvusLint)) + { + __corvusLint.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TestUtf8, out Corvus.DenoBenchmark.Current.DenoSchema.ConfigurationForDenoTest.Mutable __corvusTest)) + { + __corvusTest.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.ADefinitionOfAScopedRemapping.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.ADefinitionOfAScopedRemapping.cs index 9305c4b20ec..698c8498467 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.ADefinitionOfAScopedRemapping.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.ADefinitionOfAScopedRemapping.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public ADefinitionOfAScopedRemapping Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.cs index 2df5f8ba4b9..493c324a9a3 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.ScopesEntity.cs @@ -353,6 +353,12 @@ private void CheckValidInstance() public ScopesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.cs index 921a7867dd6..4a1a5e76ace 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/DenoSchema.cs @@ -614,6 +614,12 @@ private void CheckValidInstance() public DenoSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonBoolean.cs index 9c93cfdd35e..fec5155cdf5 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonString.cs index d689306592d..d021b26a0ed 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/corvusjson-jsonschema.lock index a7c16e8442e..07886ecd2de 100644 --- a/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.DenoBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:25.3159228\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:19:59.9269931\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.Mutable.cs index b77d1b59a57..f3740155d60 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.Mutable.cs @@ -347,6 +347,36 @@ public void SetVersion(scoped in Corvus.DependabotBenchmark.Current.DependabotSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionUtf8, out IJsonDocument? _, out int _)) + { + SetVersion(Corvus.DependabotBenchmark.Current.DependabotSchema.VersionEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPack_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPack_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.Mutable.cs index c45f56164c5..8f60d9e7f59 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPack_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPack_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.Mutable.cs @@ -339,6 +339,37 @@ public bool RemoveMatchValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MatchValueUtf8, out Corvus.DependabotBenchmark.Current.DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.MatchEntity.Mutable __corvusMatchValue)) + { + __corvusMatchValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.cs index d6a57aebd28..a8a7affede4 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public MatchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.MatchEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.MatchEntity.cs index f0cda59c2ac..305d380d879 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.MatchEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.MatchEntity.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public MatchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageM_._AutomergedUpdatesEntity.MatchEntity.DependencyTypeEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageM_._AutomergedUpdatesEntity.MatchEntity.DependencyTypeEntity.cs index e0f8bb6c0d4..124364c6204 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageM_._AutomergedUpdatesEntity.MatchEntity.DependencyTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageM_._AutomergedUpdatesEntity.MatchEntity.DependencyTypeEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public DependencyTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.Mutable.cs index ee3db303dad..eeb02650b76 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.Mutable.cs @@ -339,6 +339,37 @@ public bool RemoveMatchValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MatchValueUtf8, out Corvus.DependabotBenchmark.Current.DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.Mutable __corvusMatchValue)) + { + __corvusMatchValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.Mutable.cs index b74430ae95a..ee0d2fe4578 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.Mutable.cs @@ -339,6 +339,37 @@ public bool RemoveMatchValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MatchValueUtf8, out Corvus.DependabotBenchmark.Current.DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.MatchEntity.Mutable __corvusMatchValue)) + { + __corvusMatchValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManag_._AutomergedUpdatesEntity.MatchEntity.UpdateTypeEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManag_._AutomergedUpdatesEntity.MatchEntity.UpdateTypeEntity.cs index d9e1e7ee7f1..c07093bce1a 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManag_._AutomergedUpdatesEntity.MatchEntity.UpdateTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManag_._AutomergedUpdatesEntity.MatchEntity.UpdateTypeEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public UpdateTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerA_._AllowedUpdatesEntity.MatchEntity.WhichUpdatesToDo.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerA_._AllowedUpdatesEntity.MatchEntity.WhichUpdatesToDo.cs index a4f6273b840..7ef720949f3 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerA_._AllowedUpdatesEntity.MatchEntity.WhichUpdatesToDo.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerA_._AllowedUpdatesEntity.MatchEntity.WhichUpdatesToDo.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public WhichUpdatesToDo Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._AutomergedUpdatesEntity.MatchEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._AutomergedUpdatesEntity.MatchEntity.Mutable.cs index 38f910dcb4f..984d943f00e 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._AutomergedUpdatesEntity.MatchEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._AutomergedUpdatesEntity.MatchEntity.Mutable.cs @@ -408,6 +408,31 @@ public bool RemoveUpdateType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._AllowedUpdatesEntity.MatchEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._AllowedUpdatesEntity.MatchEntity.Mutable.cs index 3acd94a2bff..d3f67a7449f 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._AllowedUpdatesEntity.MatchEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._AllowedUpdatesEntity.MatchEntity.Mutable.cs @@ -418,6 +418,36 @@ public bool RemoveUpdateType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UpdateTypeUtf8, out IJsonDocument? _, out int _)) + { + SetUpdateType(Corvus.DependabotBenchmark.Current.DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.WhichUpdatesToDo.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._IgnoredUpdatesEntity.MatchEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._IgnoredUpdatesEntity.MatchEntity.Mutable.cs index 9343de50151..20ef2433f68 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._IgnoredUpdatesEntity.MatchEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._IgnoredUpdatesEntity.MatchEntity.Mutable.cs @@ -352,6 +352,31 @@ public bool RemoveVersionRequirement() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.cs index ac21e360e3a..cdd5c6ec4d3 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDirectoryAndPackageManagerAndUpdateSchedu public readonly partial struct AllowedUpdatesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public AllowedUpdatesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.cs index 15d2caa9608..9d0dd5e761f 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDirectoryAndPackageManagerAndUpdateSchedu public readonly partial struct AutomergedUpdatesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public AutomergedUpdatesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.Mutable.cs index 6643d78034a..ac272008b59 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.Mutable.cs @@ -399,6 +399,31 @@ public bool RemovePrefixDevelopment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.cs index 8eaa8948030..0ef1ca7d9fa 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.cs @@ -396,6 +396,12 @@ private void CheckValidInstance() public CommitMessageEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.DefaultLabArray.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.DefaultLabArray.cs index c7c2d8e6b7c..7a514e94877 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.DefaultLabArray.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.DefaultLabArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDirectoryAndPackageManagerAndUpdateSchedu public readonly partial struct DefaultLabArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public DefaultLabArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.cs index 2a5314e7fb0..d82b88b889c 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public HowOftenToCheckForUpdates Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.cs index 602d0c9bd37..704d7780338 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDirectoryAndPackageManagerAndUpdateSchedu public readonly partial struct IgnoredUpdatesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public IgnoredUpdatesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.JsonStringArray.cs index 721f573c8ba..b8d74e38e67 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDirectoryAndPackageManagerAndUpdateSchedu public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.Mutable.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.Mutable.cs index c7efd6a7f55..eebe1d91b0b 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.Mutable.cs @@ -1327,6 +1327,37 @@ public bool RemoveVersionRequirementUpdates() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommitMessageUtf8, out Corvus.DependabotBenchmark.Current.DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.Mutable __corvusCommitMessage)) + { + __corvusCommitMessage.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.ReviewersTArray.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.ReviewersTArray.cs index 35a2d66d928..6228efa1e80 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.ReviewersTArray.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.ReviewersTArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDirectoryAndPackageManagerAndUpdateSchedu public readonly partial struct ReviewersTArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ReviewersTArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.TargetBranchEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.TargetBranchEntity.cs index 35275a72a9c..09396cb87e5 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.TargetBranchEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.TargetBranchEntity.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public TargetBranchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.cs index 01a76df70f5..a62e89fa000 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public VersionRequirementUpdatesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.WhatPackageManagerToUse.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.WhatPackageManagerToUse.cs index 509a3ec0a9a..08665b0e90c 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.WhatPackageManagerToUse.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.WhatPackageManagerToUse.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public WhatPackageManagerToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.cs index a0c2398cc37..8c90f109e7c 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.cs @@ -623,6 +623,12 @@ private void CheckValidInstance() public RequiredDirectoryAndPackageManagerAndUpdateSchedule Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAnd_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.MatchEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAnd_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.MatchEntity.cs index 25830a1a146..7ba53c61fa7 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAnd_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.MatchEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAnd_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.MatchEntity.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public MatchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.cs index 07ae9269a07..3a4f790441b 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.cs @@ -21,11 +21,13 @@ public readonly partial struct DependabotSchema public readonly partial struct RequiredDirectoryAndPackageManagerAndUpdateScheduleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public RequiredDirectoryAndPackageManagerAndUpdateScheduleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._dPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._dPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.cs index f5895b7f5b4..994eb064e7a 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._dPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._dPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public AutomergedUpdatesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.cs index 63c058c6ac0..f211a927f7d 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public AllowedUpdatesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.cs index 47e46bb5a23..dbc7d23d93e 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public IgnoredUpdatesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.VersionEntity.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.VersionEntity.cs index 33a1f51ceae..93539dfa872 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.VersionEntity.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.cs index a8cc6447c61..2c3781eb600 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/DependabotSchema.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public DependabotSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonBoolean.cs index a6b893f649f..458c7e60ee6 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonInteger.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonInteger.cs index 627f86f6b76..4c3657ef418 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonInteger.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonInteger.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonString.cs index 4c81ea426ab..83e370ab88c 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/JsonString.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/corvusjson-jsonschema.lock index 0c01ba1a8f6..c2d76e28c99 100644 --- a/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.DependabotBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:26.2513265\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:01.2487836\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { @@ -36,29 +36,31 @@ "DependabotSchema.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndP_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPack_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.MatchEntity.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageM_._AutomergedUpdatesEntity.MatchEntity.DependencyTypeEntity.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMan_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManag_._AutomergedUpdatesEntity.MatchEntity.UpdateTypeEntity.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerA_._AllowedUpdatesEntity.MatchEntity.WhichUpdatesToDo.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndU_._AutomergedUpdatesEntity.MatchEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._AllowedUpdatesEntity.MatchEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._AutomergedUpdatesEntity.MatchEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._IgnoredUpdatesEntity.MatchEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpda_._MatchEntity.DependencyTypeEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._AllowedUpdatesEntity.MatchEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._IgnoredUpdatesEntity.MatchEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateS_._MatchEntity.DependencyTypeEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSc_._MatchEntity.UpdateTypeEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSc_._MatchEntity.WhichUpdatesToDo.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSched_._MatchEntity.UpdateTypeEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSched_._MatchEntity.WhichUpdatesToDo.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPacka_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.MatchEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackag_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMa_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMana_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.MatchEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageMana_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.MatchEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManag_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManag_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManage_._AutomergedUpdatesEntity.MatchEntity.DependencyTypeEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerA_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerA_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpd_._AllowedUpdatesEntity.MatchEntity.WhichUpdatesToDo.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSch_._AllowedUpdatesEntity.MatchEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSch_._AutomergedUpdatesEntity.MatchEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSch_._IgnoredUpdatesEntity.MatchEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSch_._MatchEntity.DependencyTypeEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedu_._AllowedUpdatesEntity.MatchEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedu_._IgnoredUpdatesEntity.MatchEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedu_._MatchEntity.DependencyTypeEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedul_._MatchEntity.UpdateTypeEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedul_._MatchEntity.WhichUpdatesToDo.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.CommitMessageEntity.Mutable.cs", @@ -66,8 +68,10 @@ "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.DefaultLabArray.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.DefaultLabArray.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.DefaultLabArray.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.JsonSchema.cs", @@ -81,25 +85,21 @@ "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.TargetBranchEntity.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.TargetBranchEntity.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.TargetBranchEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.WhatPackageManagerToUse.JsonSchema.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.WhatPackageManagerToUse.Mutable.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.WhatPackageManagerToUse.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackage_._AllowedUpdatesEntityArray.AllowedUpdatesEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackage_._IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAnd_._AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.MatchEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule_._y.MatchEntity.UpdateTypeEntity.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdateSchedule_._y.MatchEntity.WhichUpdatesToDo.Mutable.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAndUpdate_._AutomergedUpdatesEntity.MatchEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.RequiredDirectoryAndPackageManagerAnd_._AutomergedUpdatesEntity.MatchEntity.UpdateTypeEntity.cs", "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._dPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._edDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._edDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._irectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._toryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._uiredDirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._uiredDirectoryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.Mutable.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._uiredDirectoryAndPackageManagerAndUpdateSchedule.HowOftenToCheckForUpdates.JsonSchema.cs", - "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._uiredDirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._DirectoryAndPackageManagerAndUpdateSchedule.AllowedUpdatesEntityArray.AllowedUpdatesEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._DirectoryAndPackageManagerAndUpdateSchedule.IgnoredUpdatesEntityArray.IgnoredUpdatesEntity.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._iredDirectoryAndPackageManagerAndUpdateSchedule.VersionRequirementUpdatesEntity.JsonSchema.cs", + "DependabotSchema.RequiredDirectoryAndPackageManagerAndUpdateScheduleArray_._oryAndPackageManagerAndUpdateSchedule.AutomergedUpdatesEntityArray.AutomergedUpdatesEntity.cs", "DependabotSchema.VersionEntity.JsonSchema.cs", "DependabotSchema.VersionEntity.Mutable.cs", "DependabotSchema.VersionEntity.cs", diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalItemsEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalItemsEntity.cs index d40f59c2621..d8f0bc3b8e1 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalItemsEntity.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public AdditionalItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalPropertiesEntity.cs index c04b82817a0..2f95b6287af 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.AdditionalPropertiesEntity.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DefinitionsEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DefinitionsEntity.cs index 2de2daf3bbc..b4c9475ffcb 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DefinitionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DefinitionsEntity.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public DefinitionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.AdditionalPropertiesEntity.cs index fbce6ccf548..0d42e254be9 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.AdditionalPropertiesEntity.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.cs index 45a73324a4c..3ee1c803a51 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.DependenciesEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public DependenciesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.EnumArray.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.EnumArray.cs index 2bd857b4cb2..0458b4436fd 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.EnumArray.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.EnumArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Draft04Schema public readonly partial struct EnumArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -70,6 +72,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -283,6 +300,12 @@ private void CheckValidInstance() public EnumArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMaximumEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMaximumEntity.cs index 2fc76d75e74..4cea9775b79 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMaximumEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMaximumEntity.cs @@ -311,6 +311,12 @@ private void CheckValidInstance() public ExclusiveMaximumEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMinimumEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMinimumEntity.cs index 00343c9ca4a..7df7378665a 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMinimumEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ExclusiveMinimumEntity.cs @@ -311,6 +311,12 @@ private void CheckValidInstance() public ExclusiveMinimumEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ItemsEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ItemsEntity.cs index 5371599c7fa..6e4d250f409 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.ItemsEntity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public ItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.MultipleOfEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.MultipleOfEntity.cs index b538207b6a7..8af0cd8f0d2 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.MultipleOfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.MultipleOfEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public MultipleOfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.Mutable.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.Mutable.cs index 2d1c2b39452..4f207ba544e 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.Mutable.cs @@ -2777,6 +2777,87 @@ public bool RemoveUniqueItems() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AdditionalItemsUtf8, out IJsonDocument? _, out int _)) + { + SetAdditionalItems(Corvus.Draft04Benchmark.Current.Draft04Schema.AdditionalItemsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AdditionalPropertiesUtf8, out IJsonDocument? _, out int _)) + { + SetAdditionalProperties(Corvus.Draft04Benchmark.Current.Draft04Schema.AdditionalPropertiesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefinitionsUtf8, out IJsonDocument? _, out int _)) + { + SetDefinitions(Corvus.Draft04Benchmark.Current.Draft04Schema.DefinitionsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExclusiveMaximumUtf8, out IJsonDocument? _, out int _)) + { + SetExclusiveMaximum(Corvus.Draft04Benchmark.Current.Draft04Schema.ExclusiveMaximumEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExclusiveMinimumUtf8, out IJsonDocument? _, out int _)) + { + SetExclusiveMinimum(Corvus.Draft04Benchmark.Current.Draft04Schema.ExclusiveMinimumEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemsUtf8, out IJsonDocument? _, out int _)) + { + SetItems(Corvus.Draft04Benchmark.Current.Draft04Schema.ItemsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NotUtf8, out IJsonDocument? _, out int _)) + { + SetNot(Corvus.Draft04Benchmark.Current.Draft04Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PatternPropertiesUtf8, out IJsonDocument? _, out int _)) + { + SetPatternProperties(Corvus.Draft04Benchmark.Current.Draft04Schema.PatternPropertiesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropertiesUtf8, out IJsonDocument? _, out int _)) + { + SetProperties(Corvus.Draft04Benchmark.Current.Draft04Schema.PropertiesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UniqueItemsUtf8, out IJsonDocument? _, out int _)) + { + SetUniqueItems(Corvus.Draft04Benchmark.Current.Draft04Schema.UniqueItemsEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NotUtf8, out Corvus.Draft04Benchmark.Current.Draft04Schema.Mutable __corvusNot)) + { + __corvusNot.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PatternPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PatternPropertiesEntity.cs index ecbb875aa8c..22618b61fa0 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PatternPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PatternPropertiesEntity.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public PatternPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveInteger.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveInteger.cs index 1b3e5f5a081..8a365e67f7b 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveInteger.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveInteger.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public PositiveInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.DefaultValueType0.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.DefaultValueType0.cs index 31dd8c1f45a..362692a7a9b 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.DefaultValueType0.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.DefaultValueType0.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public DefaultValueType0 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.cs index edf79dd6f5c..cbdf6d7845d 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PositiveIntegerDefault0.cs @@ -433,6 +433,12 @@ private void CheckValidInstance() public PositiveIntegerDefault0 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PropertiesEntity.cs index 731b7e6c3d1..5762d2b0b4d 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.PropertiesEntity.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public PropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SchemaArray.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SchemaArray.cs index 749e1d1576a..fee6ddea808 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SchemaArray.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SchemaArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Draft04Schema public readonly partial struct SchemaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public SchemaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SimpleTypes.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SimpleTypes.cs index e438f304651..f8aba7898a8 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SimpleTypes.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.SimpleTypes.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SimpleTypes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.StringArray.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.StringArray.cs index ed52cd8205c..245e0b188f4 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.StringArray.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.StringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Draft04Schema public readonly partial struct StringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public StringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.SimpleTypesArray.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.SimpleTypesArray.cs index 925f421d209..c09deaf63fd 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.SimpleTypesArray.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.SimpleTypesArray.cs @@ -23,11 +23,13 @@ public readonly partial struct TypeEntity public readonly partial struct SimpleTypesArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public SimpleTypesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.cs index 81792e394f2..2b6682f0c02 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.TypeEntity.cs @@ -391,6 +391,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.UniqueItemsEntity.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.UniqueItemsEntity.cs index da4a4782288..3bb70e5f145 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.UniqueItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.UniqueItemsEntity.cs @@ -311,6 +311,12 @@ private void CheckValidInstance() public UniqueItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.cs index ebd9cafabec..b9ed600a7c0 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/Draft04Schema.cs @@ -883,6 +883,12 @@ private void CheckValidInstance() public Draft04Schema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonBoolean.cs index b256683c9ab..b5b94e5f9ee 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonNumber.cs index 2594c4e7eb3..0e12b664ed2 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonNumber.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonRegex.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonRegex.cs index 25276ef4cfe..6bda653ad2e 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonRegex.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonRegex.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonRegex Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonString.cs index 0e78593579b..a39e8adf60e 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/corvusjson-jsonschema.lock index 030e9512e9f..4a6fb05df10 100644 --- a/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.Draft04BenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:27.1795091\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:02.5583141\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.BreaksEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.BreaksEntity.cs index 488b209a0e5..43782ab3941 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.BreaksEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.BreaksEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public BreaksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ConflictsEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ConflictsEntity.cs index 92f5ebc7065..3e69c1fef92 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ConflictsEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ConflictsEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public ConflictsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.Mutable.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.Mutable.cs index e9517525394..a5f96fd9b50 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.Mutable.cs @@ -542,6 +542,31 @@ public bool RemoveSources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.cs index 05d9e425a91..52ae3fdf784 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContactInfo.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public ContactInfo Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContriArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContriArray.cs index de518ebf87d..8433d78833a 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContriArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.ContriArray.cs @@ -26,11 +26,13 @@ public readonly partial struct FabricModSchema public readonly partial struct ContriArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ContriArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.DependsEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.DependsEntity.cs index d7b0e03b367..d62f520e20f 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.DependsEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.DependsEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public DependsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.Mutable.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.Mutable.cs index fa9f44d7f05..1a0d5d154f4 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.Mutable.cs @@ -335,6 +335,36 @@ public void SetValue(scoped in Corvus.FabricModBenchmark.Current.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AdapterUtf8, out IJsonDocument? _, out int _)) + { + SetAdapter(Corvus.FabricModBenchmark.Current.FabricModSchema.Entrypoint.RequiredValue.TheLanguageAdapterToUse.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.TheLanguageAdapterToUse.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.TheLanguageAdapterToUse.cs index 24f21195a3c..1636a3d84a2 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.TheLanguageAdapterToUse.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.TheLanguageAdapterToUse.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheLanguageAdapterToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.cs index c7a64ed96f4..032f586c904 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.RequiredValue.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public RequiredValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.cs index 442f81c3175..0623941ceef 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Entrypoint.cs @@ -420,6 +420,12 @@ private void CheckValidInstance() public Entrypoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Environment.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Environment.cs index b05c17036fe..fd30fb26f7a 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Environment.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Environment.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public Environment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.PropertyNamesEntity.cs index 554d05e75b8..dddddb62ddd 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.PropertyNamesEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.cs index 709ed08a224..1b786b11eac 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.OneOf1Entity.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.cs index ea23583f951..2808f3881a4 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.IconEntity.cs @@ -420,6 +420,12 @@ private void CheckValidInstance() public IconEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.LanguageAdaptersEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.LanguageAdaptersEntity.cs index dec55bf8980..5523a2ce656 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.LanguageAdaptersEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.LanguageAdaptersEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public LanguageAdaptersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.Mutable.cs index 438d9ba140c..cc9d0e1709a 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.Mutable.cs @@ -348,6 +348,31 @@ public bool RemoveEnvironmentValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.cs index 42bc4a1f687..fb1ee630f39 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.OneOf1Entity.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.cs index bea43059032..2d24cbc87d5 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.MixinsEntity.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public MixinsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.cs index e0a37d80b8d..48f728a0294 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.MixinsEntityArray.cs @@ -21,11 +21,13 @@ public readonly partial struct FabricModSchema public readonly partial struct MixinsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public MixinsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Mutable.cs index 794146a8ccf..654ecd8a466 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Mutable.cs @@ -2158,6 +2158,43 @@ public void SetVersion(scoped in Corvus.FabricModBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContactUtf8, out Corvus.FabricModBenchmark.Current.FabricModSchema.ContactInfo.Mutable __corvusContact)) + { + __corvusContact.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EntrypointsUtf8, out Corvus.FabricModBenchmark.Current.FabricModSchema.TheEntrypointsUsedByThisMod.Mutable __corvusEntrypoints)) + { + __corvusEntrypoints.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.Mutable.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.Mutable.cs index f0fe804ea8a..1fd082d8907 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.Mutable.cs @@ -267,6 +267,31 @@ public void SetFile(scoped in Corvus.FabricModBenchmark.Current.JsonString.Sourc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.cs index db98ada8959..fcc7bbae2b4 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJar.cs @@ -363,6 +363,12 @@ private void CheckValidInstance() public NestedJar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJarArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJarArray.cs index f5fa947aaf1..a7d40798985 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJarArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.NestedJarArray.cs @@ -26,11 +26,13 @@ public readonly partial struct FabricModSchema public readonly partial struct NestedJarArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public NestedJarArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.Mutable.cs index 444b339c645..fa0cacb4253 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.Mutable.cs @@ -371,6 +371,37 @@ public void SetName(scoped in Corvus.FabricModBenchmark.Current.JsonString.Sourc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContactUtf8, out Corvus.FabricModBenchmark.Current.FabricModSchema.ContactInfo.Mutable __corvusContact)) + { + __corvusContact.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.cs index 3b9e74d515e..07d61f1c798 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.RequiredName.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.cs index 80540ccb1a3..4a5cd703976 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.Person.cs @@ -420,6 +420,12 @@ private void CheckValidInstance() public Person Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.PersonArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.PersonArray.cs index 960494929e1..3c4d13346dc 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.PersonArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.PersonArray.cs @@ -26,11 +26,13 @@ public readonly partial struct FabricModSchema public readonly partial struct PersonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public PersonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.RecommendsEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.RecommendsEntity.cs index 386c83ded56..6b801d3da72 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.RecommendsEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.RecommendsEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public RecommendsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.SuggestsEntity.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.SuggestsEntity.cs index aa907a8fd26..a113f770de4 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.SuggestsEntity.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.SuggestsEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public SuggestsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ClientEntrArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ClientEntrArray.cs index ad06c1b395a..0e6b94d8877 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ClientEntrArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ClientEntrArray.cs @@ -28,11 +28,13 @@ public readonly partial struct TheEntrypointsUsedByThisMod public readonly partial struct ClientEntrArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ClientEntrArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.EntrypointArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.EntrypointArray.cs index f8a09800f65..94e9e208c12 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.EntrypointArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.EntrypointArray.cs @@ -28,11 +28,13 @@ public readonly partial struct TheEntrypointsUsedByThisMod public readonly partial struct EntrypointArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public EntrypointArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricDataArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricDataArray.cs index 6dee6ae4700..3685e6ac1b9 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricDataArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricDataArray.cs @@ -28,11 +28,13 @@ public readonly partial struct TheEntrypointsUsedByThisMod public readonly partial struct FabricDataArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public FabricDataArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricGameArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricGameArray.cs index 94a916fa7c4..e723b01d1d1 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricGameArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.FabricGameArray.cs @@ -28,11 +28,13 @@ public readonly partial struct TheEntrypointsUsedByThisMod public readonly partial struct FabricGameArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public FabricGameArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.MainEntrypArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.MainEntrypArray.cs index e5d3899e768..8fc422dc051 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.MainEntrypArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.MainEntrypArray.cs @@ -28,11 +28,13 @@ public readonly partial struct TheEntrypointsUsedByThisMod public readonly partial struct MainEntrypArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public MainEntrypArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.Mutable.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.Mutable.cs index 3fae2d53a24..0c2e4932b20 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.Mutable.cs @@ -824,6 +824,31 @@ public bool RemoveServer() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.PreLaunchEArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.PreLaunchEArray.cs index 1aa2a2b3ca0..aa46ba52527 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.PreLaunchEArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.PreLaunchEArray.cs @@ -28,11 +28,13 @@ public readonly partial struct TheEntrypointsUsedByThisMod public readonly partial struct PreLaunchEArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public PreLaunchEArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ServerEntrArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ServerEntrArray.cs index 90f59f24629..b0ce0884b27 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ServerEntrArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.ServerEntrArray.cs @@ -28,11 +28,13 @@ public readonly partial struct TheEntrypointsUsedByThisMod public readonly partial struct ServerEntrArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ServerEntrArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.cs index cad4d06810f..179451bd4e5 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheEntrypointsUsedByThisMod.cs @@ -470,6 +470,12 @@ private void CheckValidInstance() public TheEntrypointsUsedByThisMod Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.JsonStringArray.cs index 3325b8eb332..082abcc17cf 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct TheLicenseTheModUses public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.cs index f6d12a17ca3..2b691263cce 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheLicenseTheModUses.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public TheLicenseTheModUses Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheModIdentifier.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheModIdentifier.cs index 61cb52cf3b8..13b7a3167b2 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheModIdentifier.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheModIdentifier.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public TheModIdentifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheVersionOfTheFabricModJsonSchema.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheVersionOfTheFabricModJsonSchema.cs index 2171b67abe6..b8f9619f70d 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheVersionOfTheFabricModJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.TheVersionOfTheFabricModJsonSchema.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public TheVersionOfTheFabricModJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.JsonStringArray.cs index 0c888150db4..a79a6054bb6 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct VersionRanges public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.cs index a884cbb0544..509ba046856 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.VersionRanges.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public VersionRanges Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.cs index 40ed38ccb71..8cb854a7c92 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/FabricModSchema.cs @@ -797,6 +797,12 @@ private void CheckValidInstance() public FabricModSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonObject.cs index 6d465ab5d55..a075d0e7efb 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonString.cs index 59055a57f41..7182aaa4121 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/corvusjson-jsonschema.lock index 1bb61a7b45c..22344fb0ad5 100644 --- a/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.FabricModBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:28.1449628\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:04.1831467\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 5912de979ba..91978de68d4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs index 2e0b76d834f..83cc2e3390c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs index c1b4ecb2902..506e5d69046 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs index 29561828773..01a3c66660c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs @@ -457,6 +457,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs index 5e7dfc70044..b353a9f7409 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs index d956dc5ca49..21a48acf81e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public GeoJsonLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs index a6558ecf342..341bcbea2ce 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs index e4150b49426..bf3b3f7fc81 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs index fb881ecf526..1019c94fd2b 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs @@ -457,6 +457,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs index 5f8c509d092..ea06853e32c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs index c5fa9a21c86..87988cd4814 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public GeoJsonMultiLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs index f5a84877a9f..01a997a4a95 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs index be6c68d999d..02597df5404 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs index cc3721f13ff..0088977ae0b 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs @@ -457,6 +457,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs index 330de59a4bd..8948a56d285 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs index a3d0441656f..489cd36d234 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public GeoJsonMultiPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs index 0b2e4cd1875..cbe3ea8debf 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs index ac3685693c3..e3b471d1a1e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs index c8c68e05f35..30947a81a66 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs @@ -457,6 +457,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs index 336fa267f05..cd7870d0c71 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs index 319003643f3..042f4b11cda 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public GeoJsonMultiPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs index ae13eacfb98..29323384302 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct CoordinateArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public CoordinateArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs index bc83a3147b4..e7e2f796f5f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs index 9841b18b22c..5352a13b531 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs @@ -457,6 +457,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs index bc8f871ff3f..ee19deac90b 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs index 5e6fc719612..5dbcd310756 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public GeoJsonPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index f5576a30e54..eef6e2b613f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs index daa40fea6ff..3557b8de668 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs index 19fcd40237a..964d641207d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs index 77477573f95..caf8dcea3f3 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs @@ -457,6 +457,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs index 9bffd3c7d0a..94972089999 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs index 205bb18efb3..9a87dc61f11 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public GeoJsonPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs index fc84814e699..5d656221972 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs @@ -509,6 +509,12 @@ private void CheckValidInstance() public GeometriesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs index 8d6e9ce9e30..880d976b522 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonGeometryCollection public readonly partial struct GeometriesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public GeometriesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs index c4a23b615ed..70a973ae8f4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonGeometryCollection public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs index 8ff1e9804e2..19bb22f6bc7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs @@ -451,6 +451,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs index 51507e0bed9..f40bcd09f71 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs index c1fe2ef9386..e553627f382 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public GeoJsonGeometryCollection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs index 9c66523f228..3c2d8b8b3d7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs @@ -39,11 +39,13 @@ public readonly partial struct ItemsArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -121,6 +123,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -334,6 +351,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs index 9a5125a337c..b8841d2bf93 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs @@ -37,11 +37,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct ItemsArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public ItemsArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._esEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._esEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs index b8aaf90f372..46608fe2dcf 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._esEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._esEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs index 2b9ff7d92cd..2a323c4061a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs index 19c42a40230..63f3ce1200c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._ometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._ometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 07fa83d8b20..8a5c61d3737 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._ometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._ometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._triesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._triesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index e9373cfff0a..55d08a4c19e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._triesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._triesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -35,11 +35,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs index 27440a3c2cf..05bd24b0a18 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs index a4ae35e9573..4d5c3730305 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs index d717b5c71c3..d98fcfb8d1c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs index 645b91c76d2..cd1ffcc823a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs @@ -451,6 +451,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs index efb4312aadf..f7466452867 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs index a0ce0149642..12f4fc4de3a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public GeoJsonLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index b5b1cfcd5fc..3a22f4ed7b8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs index 3acbfba6fae..2a9c016f0b1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs index f9a57ba7ad2..a2c388332ff 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs index 654a5f18f34..a37913e4ece 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs index ae68893251e..8f39f38dfc7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs @@ -451,6 +451,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs index 5e502409a4c..daf046a3d1c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs index 6b2c1ea60db..aa128cc6eaf 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public GeoJsonMultiLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs index ba8da6b991f..36e2612a9e8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs index c65fe5283b3..a72d3b5fade 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs index e9e313e868b..b2b246f8b68 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs index c26c65546a7..92d03e2168a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs @@ -451,6 +451,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs index 050349a6805..cee7947a0f6 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs index e94c74ec253..f30e03278b5 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public GeoJsonMultiPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs index c34ecc9d0be..4e8fc0dabe8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct ItemsArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs index 07c5fb4945e..43fc0908312 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs @@ -31,11 +31,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct ItemsArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public ItemsArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index a3193288ce9..478d47f3fc8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs index 43e810ea138..7a1e5e2a0c8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs index 5e7250deaf5..b96e52a5775 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs index ac24c179477..ae60b2be02e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs @@ -451,6 +451,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs index 8614a10187b..af087736662 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs index d88e0f78e3a..8143097d1d7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public GeoJsonMultiPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs index aabfe0a8287..0c41ba576b9 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct CoordinateArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public CoordinateArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs index 557bb58c3e6..f71ee2d720d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs index 5a4d5476adc..e2a047e9774 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs @@ -451,6 +451,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs index 065ba0f7226..c85cc64f633 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs index 68dfee744f4..0cddfe6bafa 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public GeoJsonPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 731f38e2eba..b8a71d85154 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 625a8df125d..dea771c6302 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -29,11 +29,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs index 153ffa79baf..b70606bd71a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs index 0ba941d109a..b02f3e23c6e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs index ef5d4dc078b..dcb91bf5af8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs @@ -451,6 +451,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs index b02e77ebbdc..6799b94bbc5 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs index c2ee45cf302..111e263f2aa 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public GeoJsonPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.cs index 088e1741172..aabea2d4991 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.GeometryEntity.cs @@ -530,6 +530,12 @@ private void CheckValidInstance() public GeometryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.IdEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.IdEntity.cs index e514cc01dbd..6b3dc508182 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.IdEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.IdEntity.cs @@ -453,6 +453,12 @@ private void CheckValidInstance() public IdEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.JsonNumberArray.cs index 227755d041d..d690a8b32cc 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonFeature public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.Mutable.cs index f5b960894bd..dfbc857e32c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.Mutable.cs @@ -594,6 +594,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.PropertiesEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.PropertiesEntity.cs index 36b0d5875f3..9f9d9c108d0 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.PropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.PropertiesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public PropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.TypeEntity.cs index 501d2d30074..8685e8fe7f0 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.cs index 8be4cdbb1bd..f2fc983f58d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeature.cs @@ -434,6 +434,12 @@ private void CheckValidInstance() public GeoJsonFeature Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 700d98631f7..cccbbacc920 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -41,11 +41,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -123,6 +125,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -336,6 +353,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs index 1084dcfd0e3..68ce50ece23 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs @@ -461,6 +461,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs index ab0da88b62d..42670ac5400 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs @@ -513,6 +513,12 @@ private void CheckValidInstance() public GeometriesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs index e59a601945e..3310f9a8676 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonGeometryCollection public readonly partial struct GeometriesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public GeometriesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs index 89550b8e2c7..46f75d3cb0f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonGeometryCollection public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs index a9351fa3abf..2353cf77f43 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Mutable.cs @@ -455,6 +455,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs index 662d0e940d8..1181265e567 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs index 3133ada575a..e70da2aebe7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public GeoJsonGeometryCollection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs index eb5ce7a20ae..5df0ba7fd42 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs index 94bbd579377..5e38b637799 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs index e3dbc4d8338..f6ffa0dcf17 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs index 66ef3c306be..88eecd3e783 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.Mutable.cs @@ -455,6 +455,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs index f650667158b..b422d034211 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs index 70ebfb3dd29..132cce7a3b6 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public GeoJsonLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs index a6ef8a7f491..52ab73dc731 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs index 7bd940f5575..3498611829d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs index f935bd55e37..13f0584dc87 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs index cd6c166a7c2..c324b79c32c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.Mutable.cs @@ -455,6 +455,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs index 1c4fb386e17..eedecec48c4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs index b745c37ce92..b2baf7eba7f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public GeoJsonMultiLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs index 80ba74f4327..480965c2deb 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs index aeca0da8e7b..a8dfae25af3 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs index 08eea6a5195..8a3d3e05eac 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs index 2725677f779..1c4c5065137 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.Mutable.cs @@ -455,6 +455,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs index 27dcf03b825..b58d1d6b27a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs index d432ecbf690..e71179d34b4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPoint.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public GeoJsonMultiPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs index 4fde4fa0d56..821beebf1ce 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs @@ -35,11 +35,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct ItemsArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public ItemsArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 09c5b0f8959..bd0457f563a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs index 6e54a88280e..0918a08fb96 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs index 59f6ae9afb2..905452434e3 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs index dc60e76d5f7..bdd64bb7df1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.Mutable.cs @@ -455,6 +455,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs index ccfbad4c601..51859cb94b8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs index fe55a86e80d..4c8ae20aea1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiPolygon.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public GeoJsonMultiPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs index 94f1da5667c..92edc7f1e13 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.CoordinateArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct CoordinateArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public CoordinateArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs index 5651f56a9f8..077fd491e0c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs index 96f1502c433..9135c8ff21c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.Mutable.cs @@ -455,6 +455,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs index f0a7253bd7a..b79c3371efa 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs index 63a3ee5d72d..f33f6d0447c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public GeoJsonPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 48d0dab08d9..fade30ef4c0 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -35,11 +35,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index ac72e131722..f99a977ff16 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs index d534f36123b..cd8680c53e9 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs index 042afede86b..f77f811814d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs index da84503ba49..9525826d38b 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.Mutable.cs @@ -455,6 +455,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs index 1be555c356a..fd869dea6a2 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs index 343fd5815d5..17d909f2960 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.cs @@ -405,6 +405,12 @@ private void CheckValidInstance() public GeoJsonPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.cs index 13351d15467..a7a37c65d68 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.cs @@ -534,6 +534,12 @@ private void CheckValidInstance() public GeometryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.IdEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.IdEntity.cs index 4a61caa99ac..96977440e02 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.IdEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.IdEntity.cs @@ -457,6 +457,12 @@ private void CheckValidInstance() public IdEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.JsonNumberArray.cs index ed3ff4fea10..ad9b8add06f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct GeoJsonFeature public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Mutable.cs index 517470783ff..44ecf4c765d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Mutable.cs @@ -598,6 +598,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.PropertiesEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.PropertiesEntity.cs index 99f06659a12..10eaec81cf4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.PropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.PropertiesEntity.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public PropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.TypeEntity.cs index 7029547d388..44cc2c94eea 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.cs index a61f0f5c2cd..5866232ec77 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.cs @@ -438,6 +438,12 @@ private void CheckValidInstance() public GeoJsonFeature Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._Collection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._Collection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs index 1aeb5505737..f04e93b688b 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._Collection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._Collection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs index d71a2cb5725..58bd056e829 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public GeoJsonMultiLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs index 08a1cd224b4..be766e64558 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs index 1b3784318c6..eb1c97151fc 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs @@ -461,6 +461,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs index cef7c01003b..be1877c71c5 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs @@ -461,6 +461,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs index b7ffa862496..d5adc369860 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs index 3eb88efe407..773aedc49e3 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._JsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._JsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs index 345afb470fb..ee4146d71ee 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._JsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._JsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct ItemsArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs index c565f097e44..e917b6a3bf2 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs index 4b8e6c95c4d..a31dc4a6b0f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs @@ -41,11 +41,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct ItemsArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public ItemsArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 8771b1a05a6..2e182c9a676 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -39,11 +39,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs index f25e8db2cca..3a427fea24d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public GeoJsonPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index ef3d4dbb877..a1c0d0c92f9 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -35,11 +35,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs index de83248f136..97e22e28c14 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs @@ -39,11 +39,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -121,6 +123,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -334,6 +351,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs index 770c231d102..dda96f2d27f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs @@ -39,11 +39,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -121,6 +123,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -334,6 +351,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ion.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ion.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs index 3187fa9cd1c..8542101835b 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ion.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ion.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs index c98fa3c085a..0cecdeb9c58 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public GeoJsonMultiPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs index 4b0d32b51ca..d15ea87e36e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs index 13584d894aa..7c790680478 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs index 5f5e0fb19c4..40ae8250da4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs index b6734684648..f7e2e31eea4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs index f2e9bdd53ff..0dcc137e43a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs index 33b1822259c..7d5a681b3f1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public GeoJsonLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs index 54f4118c112..8a1e987b190 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public GeoJsonMultiPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs index 8bdde2685d1..85b6f3f85ae 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs @@ -461,6 +461,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs index 28a19b49f74..2f9be6a2d31 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs @@ -461,6 +461,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs index 6b333fab8d1..fcc8ca9d2fa 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs index 86a249818c9..a2026507d1e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs index adfa75674b7..7fd0242fba3 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs index e136cd0c756..daf50bdb27a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct CoordinateArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public CoordinateArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs index 58a14a3f89c..49f3b331c61 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._riesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._riesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index c90bd2a4089..100b1d92b58 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._riesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._riesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -41,11 +41,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -123,6 +125,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -336,6 +353,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs index d48f30385ac..4020cadd718 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public GeoJsonPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 015a262f795..a14fbf05083 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -39,11 +39,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs index 10819ae62e7..d3fcea6cd30 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs @@ -461,6 +461,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs index a4a887699b4..4e2e1baf455 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs @@ -39,11 +39,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs index 0b5e0b7bedf..707a5f1657d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._yCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._yCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs index 89757a22dc0..9ec54c52378 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._yCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._yCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs @@ -37,11 +37,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature__._onMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray1.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature__._onMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray1.cs index 3f80fc59ef8..1904d83cde1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature__._onMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray1.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature__._onMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray1.cs @@ -43,11 +43,13 @@ public readonly partial struct ItemsArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -125,6 +127,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -338,6 +355,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.cs index bb8eaba5ecf..ec94464e573 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonFeatureCollection public readonly partial struct GeoJsonFeatureArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public GeoJsonFeatureArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.JsonNumberArray.cs index 161033aa344..dd7e944562e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonFeatureCollection public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.Mutable.cs index a40469909d2..a652b6eb0c1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.TypeEntity.cs index fe625c295a8..9363ce66fec 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.cs index 67d2224c551..663a7799e7e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonFeatureCollection.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonFeatureCollection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs index cce69696240..1ebe668d3d8 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs index 14174fb1890..072f7ff0ac7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs index ff48a45c084..3e21511fc7a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs index e490f73fef6..ad299ed3e2e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs @@ -453,6 +453,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs index 498dd416d38..1da03d08c1f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs index 04dd17bc784..8c364bb1c50 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public GeoJsonLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 874baaba2a8..cf1693efbb3 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs index b0193a04709..7ecb8b8f349 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs @@ -31,11 +31,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs index 8bbfb311504..bd16961dc8a 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs index 471197e0331..0e59d9e66b3 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs index 181da83593e..719dfb9ad78 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs @@ -453,6 +453,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs index 4ebec7ee4f2..f8332924764 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs index 5df99ac14a1..2a6bbeda0f6 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public GeoJsonMultiLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs index de196e3f98a..275d1198786 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs @@ -31,11 +31,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -113,6 +115,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -326,6 +343,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs index 6bc7627f7d4..c8b5da86420 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs index ea42e193e52..9e7571aa158 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs index 6e0053347b3..874421846da 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs @@ -453,6 +453,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs index b2567a4702b..a963203b1de 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs index 9f802b02273..907cd822c8e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public GeoJsonMultiPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs index c19fdc50bae..92b90f59593 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs @@ -33,11 +33,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct ItemsArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public ItemsArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 4737a5a068b..14978df49aa 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -31,11 +31,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs index 5efa61b9d64..e93beb9fe2e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs index 5128818f2e7..be747e5d7e0 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs index 99f97c48078..2772c995532 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs @@ -453,6 +453,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs index c8d736c3e3a..48daa6a19e9 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs index 087d946cda0..a77c516c7f9 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public GeoJsonMultiPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs index f79b9d99482..8efe9f1030e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct CoordinateArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public CoordinateArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs index 1c8be94f587..8a67196cf35 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs index 64d3eb6d045..1144afd3afe 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs @@ -453,6 +453,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs index 5e5b9693cf4..2e7279b4f84 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs index 5a36d00a574..6f59fd2c26e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public GeoJsonPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 546156fea36..7faf49ca123 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -33,11 +33,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -115,6 +117,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -328,6 +345,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index d63f8337399..5dd9f295062 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -31,11 +31,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs index ef1977a46cb..3f899f02b43 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs index fe8362d06d1..bf9ed3b25d9 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs index ad5f5acc53b..ef80c385e43 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs @@ -453,6 +453,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs index e0e49a4573d..b13fbc8e353 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs index 9ebd8ef0847..92bb1ad1f3f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public GeoJsonPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs index 061bf837fc4..ad90d531e4e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs @@ -505,6 +505,12 @@ private void CheckValidInstance() public GeometriesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._ultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._ultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs index 2f69b88119c..3feca30a2f4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._ultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._ultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs @@ -35,11 +35,13 @@ public readonly partial struct ItemsArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.cs index c267434788f..8b591e6bf57 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonGeometryCollection public readonly partial struct GeometriesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public GeometriesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.JsonNumberArray.cs index 16e5188c9c6..e7f26e696da 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonGeometryCollection public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.Mutable.cs index 1b2fa2a7f52..4553638aa27 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.TypeEntity.cs index b0066d0d50e..1ef25190c46 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.cs index 39846a04703..ef2b043c44f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonGeometryCollection.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonGeometryCollection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs index d4e0925bf99..46a2390f5b5 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.cs index 518aca8ae7c..ba4d70ee8cc 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.JsonNumberArray.cs index 02565e2f6ca..48feea7bf65 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.Mutable.cs index f1243744cd4..b3a71963119 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.TypeEntity.cs index c02b9293b8f..7a0c3958a55 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.cs index 64b08f1a0f6..9812d634480 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonLineString.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 0ce1aa3ff7c..6505c991178 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs index 8d864af2c94..529e44693b5 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -316,6 +333,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.cs index cb3c39816f9..5b052d9d1fb 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.JsonNumberArray.cs index a952b65abf9..fabb8ef22da 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonMultiLineString public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.Mutable.cs index 6d857c8dd35..2879e79eee1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.TypeEntity.cs index ae2a4fa8073..3869dd503bd 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.cs index 1c6af0ee71a..ce82fd5d11d 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiLineString.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonMultiLineString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs index c241da0b2f7..040ef5f8ce1 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -107,6 +109,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -320,6 +337,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.cs index 374bac3d569..3cc9675cd55 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.JsonNumberArray.cs index d7671c04cab..c5fd7ed74bf 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonMultiPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.Mutable.cs index 2882f529fe6..0e5862a30b2 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.TypeEntity.cs index bb55d856abf..59cc816f91b 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.cs index b53fd7aa622..c47bc35c89c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPoint.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonMultiPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs index 0b7b76cb2f2..d9c4bbf1757 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs @@ -29,11 +29,13 @@ public readonly partial struct ItemsArray2Array public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -111,6 +113,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -324,6 +341,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs index 6922a085b90..b5ba29d2b43 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs @@ -27,11 +27,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct ItemsArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public ItemsArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 0f64a5f2805..c2c71ded9ed 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -316,6 +333,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.cs index 08d290cfab9..e23c93866aa 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.JsonNumberArray.cs index 39199e913af..71f2a5e4ae7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonMultiPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.Mutable.cs index deea1c369f0..0ec15bc5218 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.TypeEntity.cs index eaaa9fa16e8..c81b0dbc5f2 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.cs index c572b02d71b..807cd77cf63 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonMultiPolygon.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonMultiPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.CoordinateArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.CoordinateArray.cs index 14274ce006d..6f4504ecf81 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.CoordinateArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.CoordinateArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct CoordinateArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public CoordinateArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.JsonNumberArray.cs index 4dbc99e9d9a..91bbfa8fab6 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonPoint public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.Mutable.cs index a3dc4e5e920..874b10f6c04 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.TypeEntity.cs index 06c99a55753..fcf1165fbf6 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.cs index 35557596f77..7863e5a351f 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPoint.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonPoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs index 838293ce985..c90cddf88e5 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs @@ -27,11 +27,13 @@ public readonly partial struct ItemsArrayArray public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -109,6 +111,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -322,6 +339,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs index 6d972d87dcc..7762a3db5a7 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs @@ -25,11 +25,13 @@ public readonly partial struct CoordinatesArray2Array public readonly partial struct ItemsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -316,6 +333,12 @@ private void CheckValidInstance() public ItemsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.cs index e35019b87c0..2c3d4e1e68e 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.CoordinatesArray2Array.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct CoordinatesArray2Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -101,6 +103,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -314,6 +331,12 @@ private void CheckValidInstance() public CoordinatesArray2Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.JsonNumberArray.cs index 091627bc7d5..f3f4a4df735 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct GeoJsonPolygon public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.Mutable.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.Mutable.cs index 7a276a2fc51..fc3a454ec15 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.Mutable.cs @@ -447,6 +447,31 @@ public void SetType(scoped in Corvus.GeoJsonBenchmark.Current.GeoJsonSchema.GeoJ _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.TypeEntity.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.TypeEntity.cs index 9ebf9a1f96d..4a4a2b328a4 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.cs index d27c853194b..211c5895211 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.GeoJsonPolygon.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public GeoJsonPolygon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.cs index 0c8346c79dd..d4354bc2301 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/GeoJsonSchema.cs @@ -579,6 +579,12 @@ private void CheckValidInstance() public GeoJsonSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNull.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNull.cs index 41a57c9dd19..4d0c4eefb9c 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNull.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNull.cs @@ -256,6 +256,12 @@ private void CheckValidInstance() public JsonNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNumber.cs index 1f9d3602205..6f7f5631ae9 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonNumber.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonObject.cs index 728a1169f6a..57f4c1b8391 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonString.cs index 008db6f0568..303ef4d33c2 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/corvusjson-jsonschema.lock index 69006ca3135..ad551a94341 100644 --- a/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.GeoJsonBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:29.2831620\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:06.0595778\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { @@ -33,22 +33,24 @@ "generatedFiles": [ "CorvusJsonSchemaProgram.cs", "Corvus__UnionAttribute.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Ge_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geo_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geomet_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometr_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometr_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometri_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometri_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometrie_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesE_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEn_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEnt_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEnti_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Ge_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geom_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geome_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometr_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometri_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesE_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEn_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEn_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEnt_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEnt_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEnti_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntit_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntit_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntit_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityA_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityAr_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArr_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs", @@ -61,6 +63,7 @@ "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.JsonSchema.cs", @@ -72,6 +75,7 @@ "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs", @@ -84,6 +88,7 @@ "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs", @@ -127,9 +132,11 @@ "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometries_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometries_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometries_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntity_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometries_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometries_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometries_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.Geometries_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.JsonNumberArray.cs", @@ -139,14 +146,7 @@ "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._esEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._ometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._triesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs", + "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection_._metriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.GeometryEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs", @@ -264,50 +264,55 @@ "GeoJsonSchema.GeoJsonFeature.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeature.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeature.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_.__GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.Mutable1.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geo_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geo_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geo_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geo_.__CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema1.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_.__GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema1.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_.__CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable1.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEn_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEn_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEn_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.G_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Ge_.__GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geo_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geo_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geom_.__GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geome_.__GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_._GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geomet_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometr_.__GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.Mutable1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryE_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEn_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEn_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnt_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnt_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnt_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnt_.__CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEnti_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntit_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs", @@ -338,6 +343,7 @@ "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonLineString.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs", @@ -396,6 +402,8 @@ "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPoint.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", @@ -415,11 +423,26 @@ "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._on.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometry_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometry_.__GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._ction.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._lection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._on.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._on.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._on.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._on.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._on.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.GeometryEntity_._tion.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometry_._GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometry_._GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometry_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.Geometry_.__CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema1.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.IdEntity.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.IdEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.IdEntity.cs", @@ -435,66 +458,43 @@ "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._Collection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.TypeEntity.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._JsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_.__GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable1.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_.__GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema1.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._eometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._eometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ion.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonSchema.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._riesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._sonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._yCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature__._oJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema1.cs", - "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature__._onMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.CoordinateArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPoint.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.ItemsArrayArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._GeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_.__GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray1.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._eometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._etryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._iesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._llection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._metryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.Mutable.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.TypeEntity.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._oJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.CoordinatesArray2Array.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.JsonSchema.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.TypeEntity.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._onGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._ryEntity.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._tryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.CoordinatesArray2Array.cs", + "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.GeoJsonFeature_._yCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.GeoJsonFeatureArray.cs", @@ -507,6 +507,7 @@ "GeoJsonSchema.GeoJsonFeatureCollection.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonFeatureCollection.TypeEntity.cs", "GeoJsonSchema.GeoJsonFeatureCollection.cs", + "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJs_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.CoordinatesArray2Array.JsonNumberArray.cs", @@ -522,6 +523,8 @@ "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.TypeEntity.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonLineString.cs", + "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonM_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable.cs", + "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", @@ -554,6 +557,7 @@ "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.TypeEntity.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPoint.cs", + "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.JsonSchema.cs", @@ -601,14 +605,10 @@ "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.TypeEntity.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.GeoJsonPolygon.cs", - "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.Geo_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.JsonSchema.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity.cs", - "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._JsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonSchema.cs", - "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._onMultiLineString.CoordinatesArray2Array.ItemsArrayArray.JsonNumberArray.JsonSchema.cs", - "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._ultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs", + "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.GeometriesEntity_._JsonMultiPolygon.CoordinatesArray2Array.ItemsArrayArray.ItemsArray2Array.JsonNumberArray.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.JsonSchema.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.Mutable.cs", "GeoJsonSchema.GeoJsonGeometryCollection.GeometriesEntityArray.cs", diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.JsonStringArray.cs index 2edc5c64f47..7bffc13d9ac 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigureJetBrainsIntegration public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.Mutable.cs index 0b9d27b83b7..855fd0d5700 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.Mutable.cs @@ -1057,6 +1057,79 @@ public bool RemoveWebstorm() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ClionUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusClion)) + { + __corvusClion.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GolandUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusGoland)) + { + __corvusGoland.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IntellijUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusIntellij)) + { + __corvusIntellij.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PhpstormUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusPhpstorm)) + { + __corvusPhpstorm.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PycharmUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusPycharm)) + { + __corvusPycharm.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RiderUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusRider)) + { + __corvusRider.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RubymineUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusRubymine)) + { + __corvusRubymine.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WebstormUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.Mutable __corvusWebstorm)) + { + __corvusWebstorm.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.cs index e4255049aed..f507947e43b 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureJetBrainsIntegration.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public ConfigureJetBrainsIntegration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.JsonStringArray.cs index f1353c89b10..1b7edfeb905 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigureVsCodeIntegration public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.Mutable.cs index c6a21bbcc0a..d79d3017c1f 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.Mutable.cs @@ -241,6 +241,31 @@ public bool RemoveExtensions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.cs index fa5ed67eee8..7b08dd52df7 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfigureVsCodeIntegration.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public ConfigureVsCodeIntegration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.Mutable.cs index 2ece4e91286..847fb0c98f9 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.Mutable.cs @@ -241,6 +241,37 @@ public bool RemovePrebuilds() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrebuildsUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.Mutable __corvusPrebuilds)) + { + __corvusPrebuilds.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddCheckEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddCheckEntity.cs index 0ec096e8df2..c52959b6067 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddCheckEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddCheckEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public AddCheckEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddLabelEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddLabelEntity.cs index 0eb831ccc45..e8780aef036 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddLabelEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.AddLabelEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public AddLabelEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.Mutable.cs index be499fa5cee..07d0ea1a186 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.Mutable.cs @@ -718,6 +718,31 @@ public bool RemovePullRequestsFromForks() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.cs index 264726a1f0f..b5af1485514 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.PrebuildsEntity.cs @@ -535,6 +535,12 @@ private void CheckValidInstance() public PrebuildsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.cs index a7abd2f9ddb..f3b849b3611 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public ConfiguresGitpodSGitHubApp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.Mutable.cs index 09a4b5b6526..4671d0f74a8 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.Mutable.cs @@ -332,6 +332,31 @@ public bool RemoveSoftLimit() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.cs index 487167a1739..07cd532143d 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.CoreDumpEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public CoreDumpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.GitConfigEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.GitConfigEntity.cs index d9fa32e1436..09eb6cef1bf 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.GitConfigEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.GitConfigEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public GitConfigEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.Mutable.cs index 3b6add0be9a..e29ffac20cd 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.Mutable.cs @@ -207,6 +207,31 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.VersionEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.VersionEntity.cs index 45ee335f339..5a7f7525231 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.VersionEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.cs index b40e9aca30b..5c70b98d75a 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.cs @@ -294,6 +294,12 @@ private void CheckValidInstance() public EnableWarmingUpOfJetBrainsBackendInPrebuilds Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.JsonStringArray.cs index a2be51f3bac..717579665a4 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JetbrainsProduct public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.Mutable.cs index 36057c4d7ca..1110df74b2d 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.Mutable.cs @@ -409,6 +409,37 @@ public bool RemoveVmoptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrebuildsUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.JetbrainsProduct.EnableWarmingUpOfJetBrainsBackendInPrebuilds.Mutable __corvusPrebuilds)) + { + __corvusPrebuilds.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.cs index 9fdfa84b97e..9b7f7b8aa44 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.JetbrainsProduct.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public JetbrainsProduct Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.Mutable.cs index 0f709e6555c..7f2bfbf7473 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.Mutable.cs @@ -1318,6 +1318,66 @@ public bool RemoveWorkspaceLocation() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImageUtf8, out IJsonDocument? _, out int _)) + { + SetImage(Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CoreDumpUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.CoreDumpEntity.Mutable __corvusCoreDump)) + { + __corvusCoreDump.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GithubUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.ConfiguresGitpodSGitHubApp.Mutable __corvusGithub)) + { + __corvusGithub.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImageUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.Mutable __corvusImage)) + { + __corvusImage.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JetbrainsUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.ConfigureJetBrainsIntegration.Mutable __corvusJetbrains)) + { + __corvusJetbrains.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VscodeUtf8, out Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.ConfigureVsCodeIntegration.Mutable __corvusVscode)) + { + __corvusVscode.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.Mutable.cs index 8d8a8a61d4d..c9971d72bbb 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.Mutable.cs @@ -526,6 +526,36 @@ public bool RemoveVisibility() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VisibilityUtf8, out IJsonDocument? _, out int _)) + { + SetVisibility(Corvus.GitpodConfigurationBenchmark.Current.GitpodConfigurationSchema.RequiredPortArray.RequiredPort.VisibilityEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.OnOpenEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.OnOpenEntity.cs index 51a41616df6..65943a0344c 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.OnOpenEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.OnOpenEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public OnOpenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.PortEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.PortEntity.cs index 55a3ea5c2e8..3ea4d79cf4f 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.PortEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.PortEntity.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public PortEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.TheProtocolOfWorkspacePort.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.TheProtocolOfWorkspacePort.cs index 698c9087ee4..654c5ebced9 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.TheProtocolOfWorkspacePort.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.TheProtocolOfWorkspacePort.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public TheProtocolOfWorkspacePort Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.VisibilityEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.VisibilityEntity.cs index c0bf9a0bbd7..616856bab3d 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.VisibilityEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.VisibilityEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public VisibilityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.cs index c575a9db211..d78f7148f97 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.RequiredPort.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public RequiredPort Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.cs index a785d10ebfa..9d77b1807c4 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredPortArray.cs @@ -26,11 +26,13 @@ public readonly partial struct GitpodConfigurationSchema public readonly partial struct RequiredPortArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RequiredPortArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.Mutable.cs index ccf3325f558..9b38224e7bd 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.Mutable.cs @@ -262,6 +262,31 @@ public void SetUrl(scoped in Corvus.GitpodConfigurationBenchmark.Current.JsonStr _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.cs index 6c4c72c627c..a5359fdaa4b 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.RequiredUrl.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RequiredUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.cs index f412b73923e..764a0f14585 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.RequiredUrlArray.cs @@ -26,11 +26,13 @@ public readonly partial struct GitpodConfigurationSchema public readonly partial struct RequiredUrlArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RequiredUrlArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.Mutable.cs index b527a1c9e94..cf5a0fd82ae 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.Mutable.cs @@ -705,6 +705,31 @@ public bool RemovePrebuild() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.OpenInEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.OpenInEntity.cs index 5412d7bf1d3..50a3d2099c8 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.OpenInEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.OpenInEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public OpenInEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.TheOpeningModeDefaultIsTabAfter.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.TheOpeningModeDefaultIsTabAfter.cs index e2cf501e292..2f44573bc37 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.TheOpeningModeDefaultIsTabAfter.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.TheOpeningModeDefaultIsTabAfter.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public TheOpeningModeDefaultIsTabAfter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.cs index 0fa83df8808..9bdef01a720 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.TasksEntity.cs @@ -436,6 +436,12 @@ private void CheckValidInstance() public TasksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.cs index 02268164fce..0c16af9d759 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TasksEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct GitpodConfigurationSchema public readonly partial struct TasksEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TasksEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.Mutable.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.Mutable.cs index 0de738d55ff..49c3d593a97 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.Mutable.cs @@ -397,6 +397,31 @@ public void SetFile(scoped in Corvus.GitpodConfigurationBenchmark.Current.JsonSt _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.cs index c1d6b0227b6..8330c23a046 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.TheDockerImageToRunYourWorkspaceIn.cs @@ -451,6 +451,12 @@ private void CheckValidInstance() public TheDockerImageToRunYourWorkspaceIn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.cs index 250430d9e4a..4106420e4e8 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/GitpodConfigurationSchema.cs @@ -536,6 +536,12 @@ private void CheckValidInstance() public GitpodConfigurationSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonBoolean.cs index 2467a15b5c0..5f81d915a65 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonNumber.cs index 0b945a72093..50506ce7130 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonNumber.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonObject.cs index 95f44b3c06a..fe632e37a9d 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonString.cs index 2c92f1cc83c..85f101a2e90 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/corvusjson-jsonschema.lock index 8c1cbd61020..d4fc9c26035 100644 --- a/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.GitpodConfigurationBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:30.1792429\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:07.8686358\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.Mutable.cs index 0d6ccc2f8fd..a862fe4490d 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.Mutable.cs @@ -338,6 +338,31 @@ public void SetGenerated(scoped in Corvus.HelmChartLockBenchmark.Current.JsonDat _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.Mutable.cs index 9170bfa7cf1..23aba3fdef6 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.Mutable.cs @@ -306,6 +306,31 @@ public void SetVersion(scoped in Corvus.HelmChartLockBenchmark.Current.JsonStrin _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.cs index d8707efbed4..fb45fc6fcdc 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.RequiredNameAndRepositoryAndVersion.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public RequiredNameAndRepositoryAndVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.cs index d44698f72a4..34b0c977c36 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.RequiredNameAndRepositoryAndVersionArray.cs @@ -29,11 +29,13 @@ public readonly partial struct HelmChartLockSchema public readonly partial struct RequiredNameAndRepositoryAndVersionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public RequiredNameAndRepositoryAndVersionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.cs index 5a4c210753b..21cd83866cc 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/HelmChartLockSchema.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public HelmChartLockSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonDateTime.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonDateTime.cs index 909062ecc88..5e258120e51 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonDateTime.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonDateTime.cs @@ -377,6 +377,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonString.cs index 1cf0d016027..c011c0071d8 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonUri.cs b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonUri.cs index 845f9e7a1fc..95f5bee5c8a 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonUri.cs +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/JsonUri.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public JsonUri Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/corvusjson-jsonschema.lock index f41f4c32ed6..6812c5edf6b 100644 --- a/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.HelmChartLockBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:31.0479340\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:09.2654171\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.Mutable.cs index d234592a898..f3864570950 100644 --- a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.Mutable.cs @@ -340,6 +340,31 @@ public bool RemoveScopes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheImportsField.cs b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheImportsField.cs index 10b399a2345..a9254902433 100644 --- a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheImportsField.cs +++ b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheImportsField.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public TheImportsField Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.AdditionalPropertiesEntity.cs index cef06d61fc5..88a99ce6d4d 100644 --- a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.AdditionalPropertiesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.cs b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.cs index 353fa2e6040..e3d67de2153 100644 --- a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.cs +++ b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.TheScopesField.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public TheScopesField Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.cs b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.cs index d86fad2484f..542c773c935 100644 --- a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.cs +++ b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/ImportmapSchema.cs @@ -305,6 +305,12 @@ private void CheckValidInstance() public ImportmapSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/JsonString.cs index 04516113751..1190ccfdb4f 100644 --- a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/corvusjson-jsonschema.lock index b1cff20f98c..1a19db5b462 100644 --- a/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.ImportmapBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:31.9044102\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:10.5412534\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.Mutable.cs index 99cd4a1eeed..d6fb00b6ee3 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.Mutable.cs @@ -314,6 +314,37 @@ public bool RemoveEnv() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnvUtf8, out Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.Mutable __corvusEnv)) + { + __corvusEnv.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.cs index 9f5052c9775..6930b97bada 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.AllOf1Entity.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.AutoCleanClosureEntity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.AutoCleanClosureEntity.cs index d3180d9b663..8f40416e514 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.AutoCleanClosureEntity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.AutoCleanClosureEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AutoCleanClosureEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.FailSpecWithNoExpectationsEntity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.FailSpecWithNoExpectationsEntity.cs index 520aafa3a89..ad63a613a63 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.FailSpecWithNoExpectationsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.FailSpecWithNoExpectationsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public FailSpecWithNoExpectationsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.HideDisbaledEntity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.HideDisbaledEntity.cs index 3fc7afce0e7..45edf55f292 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.HideDisbaledEntity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.HideDisbaledEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public HideDisbaledEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.Mutable.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.Mutable.cs index 17dd4960146..0bb645002bc 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.Mutable.cs @@ -740,6 +740,71 @@ public bool RemoveVerboseDeprication() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AutoCleanClosureUtf8, out IJsonDocument? _, out int _)) + { + SetAutoCleanClosure(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.AutoCleanClosureEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FailSpecWithNoExpectationsUtf8, out IJsonDocument? _, out int _)) + { + SetFailSpecWithNoExpectations(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.FailSpecWithNoExpectationsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HideDisbaledUtf8, out IJsonDocument? _, out int _)) + { + SetHideDisbaled(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.HideDisbaledEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RandomUtf8, out IJsonDocument? _, out int _)) + { + SetRandom(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.WhetherToRandomizeSpecExecutionOrder.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SeedUtf8, out IJsonDocument? _, out int _)) + { + SetSeed(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.SeedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StopOnSpecFailureUtf8, out IJsonDocument? _, out int _)) + { + SetStopOnSpecFailure(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.StopOnSpecFailureEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StopSpecOnExpectationFailureUtf8, out IJsonDocument? _, out int _)) + { + SetStopSpecOnExpectationFailure(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.WhetherToCauseSpecsToOnlyHaveOneExpectationFailure.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VerboseDepricationUtf8, out IJsonDocument? _, out int _)) + { + SetVerboseDeprication(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.VerboseDepricationEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.SeedEntity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.SeedEntity.cs index 77df0be02c7..fe6f0b67228 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.SeedEntity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.SeedEntity.cs @@ -466,6 +466,12 @@ private void CheckValidInstance() public SeedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.StopOnSpecFailureEntity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.StopOnSpecFailureEntity.cs index 49def2b3237..96412edbbb6 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.StopOnSpecFailureEntity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.StopOnSpecFailureEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public StopOnSpecFailureEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.VerboseDepricationEntity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.VerboseDepricationEntity.cs index 18867af5048..28fa647a8c0 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.VerboseDepricationEntity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.VerboseDepricationEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public VerboseDepricationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToCauseSpecsToOnlyHaveOneExpectationFailure.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToCauseSpecsToOnlyHaveOneExpectationFailure.cs index 33eadff8148..a93b6577f93 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToCauseSpecsToOnlyHaveOneExpectationFailure.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToCauseSpecsToOnlyHaveOneExpectationFailure.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhetherToCauseSpecsToOnlyHaveOneExpectationFailure Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToRandomizeSpecExecutionOrder.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToRandomizeSpecExecutionOrder.cs index 4faf22f2c4f..8b129bad4db 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToRandomizeSpecExecutionOrder.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.WhetherToRandomizeSpecExecutionOrder.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhetherToRandomizeSpecExecutionOrder Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.cs index 9a351a55a9e..16261095723 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.EnvItems.cs @@ -512,6 +512,12 @@ private void CheckValidInstance() public EnvItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.Mutable.cs index e670937e2a7..0c5bb4536d6 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.Mutable.cs @@ -1139,6 +1139,92 @@ public bool RemoveVerboseDeprication() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AutoCleanClosureUtf8, out IJsonDocument? _, out int _)) + { + SetAutoCleanClosure(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.AutoCleanClosureEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FailSpecWithNoExpectationsUtf8, out IJsonDocument? _, out int _)) + { + SetFailSpecWithNoExpectations(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.FailSpecWithNoExpectationsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HelpersUtf8, out IJsonDocument? _, out int _)) + { + SetHelpers(Corvus.JasmineBenchmark.Current.JasmineSchema.RootItems.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HideDisbaledUtf8, out IJsonDocument? _, out int _)) + { + SetHideDisbaled(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.HideDisbaledEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RandomUtf8, out IJsonDocument? _, out int _)) + { + SetRandom(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.WhetherToRandomizeSpecExecutionOrder.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SeedUtf8, out IJsonDocument? _, out int _)) + { + SetSeed(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.SeedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpecDirUtf8, out IJsonDocument? _, out int _)) + { + SetSpecDir(Corvus.JasmineBenchmark.Current.JasmineSchema.RootItems.SpecDirEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpecFilesUtf8, out IJsonDocument? _, out int _)) + { + SetSpecFiles(Corvus.JasmineBenchmark.Current.JasmineSchema.RootItems.SpecFilesJArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StopOnSpecFailureUtf8, out IJsonDocument? _, out int _)) + { + SetStopOnSpecFailure(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.StopOnSpecFailureEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StopSpecOnExpectationFailureUtf8, out IJsonDocument? _, out int _)) + { + SetStopSpecOnExpectationFailure(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.WhetherToCauseSpecsToOnlyHaveOneExpectationFailure.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VerboseDepricationUtf8, out IJsonDocument? _, out int _)) + { + SetVerboseDeprication(Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.VerboseDepricationEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnvUtf8, out Corvus.JasmineBenchmark.Current.JasmineSchema.EnvItems.Mutable __corvusEnv)) + { + __corvusEnv.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.JsonStringArray.cs index c66f4a7114e..7b1a4f41510 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.JsonStringArray.cs @@ -36,11 +36,13 @@ public readonly partial struct RootItems public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.Mutable.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.Mutable.cs index 280585b0c79..8fb01245c81 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.Mutable.cs @@ -458,6 +458,46 @@ public void SetSpecFiles(in Corvus.JasmineBenchmark.Current.JasmineSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HelpersUtf8, out IJsonDocument? _, out int _)) + { + SetHelpers(Corvus.JasmineBenchmark.Current.JasmineSchema.RootItems.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpecDirUtf8, out IJsonDocument? _, out int _)) + { + SetSpecDir(Corvus.JasmineBenchmark.Current.JasmineSchema.RootItems.SpecDirEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpecFilesUtf8, out IJsonDocument? _, out int _)) + { + SetSpecFiles(Corvus.JasmineBenchmark.Current.JasmineSchema.RootItems.SpecFilesJArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecDirEntity.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecDirEntity.cs index feadd70537b..11eefe03a32 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecDirEntity.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecDirEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public SpecDirEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecFilesJArray.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecFilesJArray.cs index 8a43f81008d..2a62a43d64c 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecFilesJArray.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.SpecFilesJArray.cs @@ -36,11 +36,13 @@ public readonly partial struct RootItems public readonly partial struct SpecFilesJArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public SpecFilesJArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.cs index 409c695da22..3ebf5be8d32 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.RootItems.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public RootItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.cs index b4337419408..924b7257459 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JasmineSchema.cs @@ -648,6 +648,12 @@ private void CheckValidInstance() public JasmineSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNull.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNull.cs index 86a8435e22a..ea2fbf013aa 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNull.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNull.cs @@ -256,6 +256,12 @@ private void CheckValidInstance() public JsonNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNumber.cs index 9a547cbfbae..65db369e8d6 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonNumber.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonString.cs index 927e92be71a..4f84fd32b0e 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/corvusjson-jsonschema.lock index 87bac402b68..31341322dcd 100644 --- a/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.JasmineBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:32.7453964\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:11.9143844\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.AllOf6Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.AllOf6Entity.cs index 9a98b9ff81c..f63a058225f 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.AllOf6Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.AllOf6Entity.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public AllOf6Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.AssumeChangesOnlyAffectDirectDependenciesEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.AssumeChangesOnlyAffectDirectDependenciesEntity.cs index df60c93f682..f0237067ec6 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.AssumeChangesOnlyAffectDirectDependenciesEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.AssumeChangesOnlyAffectDirectDependenciesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AssumeChangesOnlyAffectDirectDependenciesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.EnableVerboseLogging.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.EnableVerboseLogging.cs index d794ad3a979..ecf99ab38bf 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.EnableVerboseLogging.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.EnableVerboseLogging.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EnableVerboseLogging Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Entity.cs index 14fef680051..4d8f9f19e62 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Entity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.ForceEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.ForceEntity.cs index fc07ea04801..b8ce98e90e8 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.ForceEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.ForceEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ForceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.IncrementalEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.IncrementalEntity.cs index 54ad4dfa6f1..54e26272567 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.IncrementalEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.IncrementalEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IncrementalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.LogPathsUsedDuringTheModuleResolutionProcess.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.LogPathsUsedDuringTheModuleResolutionProcess.cs index dfdbab07307..f7eac98d367 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.LogPathsUsedDuringTheModuleResolutionProcess.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.LogPathsUsedDuringTheModuleResolutionProcess.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public LogPathsUsedDuringTheModuleResolutionProcess Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Mutable.cs index b4aef9f00ae..4204a695e27 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Mutable.cs @@ -610,6 +610,61 @@ public bool RemoveVerbose() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AssumeChangesOnlyAffectDirectDependenciesUtf8, out IJsonDocument? _, out int _)) + { + SetAssumeChangesOnlyAffectDirectDependencies(Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.AssumeChangesOnlyAffectDirectDependenciesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DryUtf8, out IJsonDocument? _, out int _)) + { + SetDry(Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Entity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ForceUtf8, out IJsonDocument? _, out int _)) + { + SetForce(Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.ForceEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IncrementalUtf8, out IJsonDocument? _, out int _)) + { + SetIncremental(Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.IncrementalEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TraceResolutionUtf8, out IJsonDocument? _, out int _)) + { + SetTraceResolution(Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.LogPathsUsedDuringTheModuleResolutionProcess.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VerboseUtf8, out IJsonDocument? _, out int _)) + { + SetVerbose(Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.EnableVerboseLogging.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.cs index 3ba52594e1e..3d0da298b34 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.cs @@ -467,6 +467,12 @@ private void CheckValidInstance() public BuildOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.Mutable.cs index 5f49fadb0c1..778f2e530e3 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.Mutable.cs @@ -309,6 +309,37 @@ public bool RemoveBuildOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuildOptionsUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Mutable __corvusBuildOptions)) + { + __corvusBuildOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.cs index 09d36670101..726da7667cd 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.BuildOptionsDefinition.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public BuildOptionsDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.Mutable.cs index 0af18bdf19c..2d218a92cae 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.Mutable.cs @@ -278,6 +278,31 @@ public bool RemoveCompileOnSave() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.cs index 2969c0ba0e8..b55064e9a44 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompileOnSaveDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public CompileOnSaveDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowAccessingUmdGlobalsFromModules.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowAccessingUmdGlobalsFromModules.cs index 177bc8ece08..3871f4fb8fa 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowAccessingUmdGlobalsFromModules.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowAccessingUmdGlobalsFromModules.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowAccessingUmdGlobalsFromModules Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs index 877dd704913..407e6aed46f 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowJsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CompositeEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CompositeEntity.cs index 2af5232080a..1800334764f 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CompositeEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CompositeEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public CompositeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourceMapFilesForEmittedJavaScriptFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourceMapFilesForEmittedJavaScriptFiles.cs index 1c2b5298b83..dcfa6364f69 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourceMapFilesForEmittedJavaScriptFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourceMapFilesForEmittedJavaScriptFiles.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public CreateSourceMapFilesForEmittedJavaScriptFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourcemapsForDTsFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourcemapsForDTsFiles.cs index 6a65c4c8c2b..ca07ebe6593 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourcemapsForDTsFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourcemapsForDTsFiles.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public CreateSourcemapsForDTsFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DeclarationEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DeclarationEntity.cs index aa0162458f0..4bb383d8940 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DeclarationEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DeclarationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DeclarationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DefaultCatchClauseVariablesAsUnknownInsteadOfAny.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DefaultCatchClauseVariablesAsUnknownInsteadOfAny.cs index f40bf824935..a7e5441a9e8 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DefaultCatchClauseVariablesAsUnknownInsteadOfAny.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DefaultCatchClauseVariablesAsUnknownInsteadOfAny.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DefaultCatchClauseVariablesAsUnknownInsteadOfAny Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingComments.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingComments.cs index c5b1eb11757..f6d26f8fdcb 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingComments.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingComments.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DisableEmittingComments Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingFileFromACompilation.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingFileFromACompilation.cs index 6fa6c62fc6a..c259043ac6e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingFileFromACompilation.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingFileFromACompilation.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DisableEmittingFileFromACompilation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErasingConstEnumDeclarationsInGeneratedCode.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErasingConstEnumDeclarationsInGeneratedCode.cs index 8e7b9f258e2..0f9bdeed530 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErasingConstEnumDeclarationsInGeneratedCode.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErasingConstEnumDeclarationsInGeneratedCode.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DisableErasingConstEnumDeclarationsInGeneratedCode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableSizeLimitEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableSizeLimitEntity.cs index 227bd1123b3..e5a22f1ef1c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableSizeLimitEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableSizeLimitEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DisableSizeLimitEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableTruncatingTypesInErrorMessages.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableTruncatingTypesInErrorMessages.cs index 93d784d7731..3e37edb349e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableTruncatingTypesInErrorMessages.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableTruncatingTypesInErrorMessages.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DisableTruncatingTypesInErrorMessages Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DownlevelIterationEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DownlevelIterationEntity.cs index e8259149888..50bec47e175 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DownlevelIterationEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DownlevelIterationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DownlevelIterationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitAV8CpuProfileOfTheCompilerRunForDebugging.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitAV8CpuProfileOfTheCompilerRunForDebugging.cs index 89c47839fee..a30fbb4b91c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitAV8CpuProfileOfTheCompilerRunForDebugging.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitAV8CpuProfileOfTheCompilerRunForDebugging.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public EmitAV8CpuProfileOfTheCompilerRunForDebugging Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitBomEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitBomEntity.cs index 14651e9d2c7..b49ef07b755 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitBomEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitBomEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EmitBomEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitEcmaScriptStandardCompliantClassFields.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitEcmaScriptStandardCompliantClassFields.cs index d886307d665..4b166ed5a14 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitEcmaScriptStandardCompliantClassFields.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitEcmaScriptStandardCompliantClassFields.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EmitEcmaScriptStandardCompliantClassFields Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs index 1246de5422e..5c8d4d024df 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EnableAllStrictTypeCheckingOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs index 1ae283b480e..2546fcda86d 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EnableErrorReportingInTypeCheckedJavaScriptFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs index da1b59dcd32..4b0262fe7ba 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EnableErrorReportingWhenALocalVariablesArenTRead Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableImportingJsonFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableImportingJsonFiles.cs index 18ac1a1d4a3..4dbf77ec6fd 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableImportingJsonFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableImportingJsonFiles.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EnableImportingJsonFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnsureThatCasingIsCorrectInImports.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnsureThatCasingIsCorrectInImports.cs index adb802c1ad0..132d6649c09 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnsureThatCasingIsCorrectInImports.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnsureThatCasingIsCorrectInImports.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EnsureThatCasingIsCorrectInImports Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EsModuleInteropEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EsModuleInteropEntity.cs index 7343f0e02e8..cf592fc42f4 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EsModuleInteropEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EsModuleInteropEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EsModuleInteropEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs index 78cf5e9042e..2ab1d81d2d0 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ExactOptionalPropertyTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExtendedDiagnosticsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExtendedDiagnosticsEntity.cs index 0a0b30295f5..b8f344cb6f3 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExtendedDiagnosticsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExtendedDiagnosticsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ExtendedDiagnosticsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.FallbackPollingEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.FallbackPollingEntity.cs index e19d3bf0bff..78e530e5949 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.FallbackPollingEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.FallbackPollingEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public FallbackPollingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportHelpersEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportHelpersEntity.cs index f6ed2d481b7..5074aa50e74 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportHelpersEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportHelpersEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ImportHelpersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportsNotUsedAsValuesEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportsNotUsedAsValuesEntity.cs index 4b945a20d04..4a35e14749d 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportsNotUsedAsValuesEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportsNotUsedAsValuesEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public ImportsNotUsedAsValuesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IncludeSourcemapFilesInsideTheEmittedJavaScript.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IncludeSourcemapFilesInsideTheEmittedJavaScript.cs index 7baf4d3c76d..9eb2da53b65 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IncludeSourcemapFilesInsideTheEmittedJavaScript.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IncludeSourcemapFilesInsideTheEmittedJavaScript.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IncludeSourcemapFilesInsideTheEmittedJavaScript Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.InlineSourcesEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.InlineSourcesEntity.cs index a246101af78..41729bc0aa5 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.InlineSourcesEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.InlineSourcesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public InlineSourcesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IsolatedModulesEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IsolatedModulesEntity.cs index eee99c915e9..47211976439 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IsolatedModulesEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IsolatedModulesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IsolatedModulesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs index 856fca153f2..02860dd9a95 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct InstructsTheTypeScriptCompilerHowToCompileTsFiles public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs index a26cb288bf6..2e10ac3bdc0 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public JsxFactoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs index 7a1d64168ec..c5992e97260 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public JsxFragmentFactoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs index 5a2f92c0254..49a7372c54b 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public JsxImportSourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs index c3280f44b88..48a6f3b250c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public KeyofStringsOnlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf0Entity.cs index 69307b93b53..745fe8cc818 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf0Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf10Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf10Entity.cs index 7190b5a9ded..9d8081935f0 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf10Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf10Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf10Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf11Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf11Entity.cs index 13f3d0ec784..b0d133d9266 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf11Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf11Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf11Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf12Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf12Entity.cs index c475bcb922b..00946049981 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf12Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf12Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf12Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf13Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf13Entity.cs index 96f2fecdcae..cb53e3e0228 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf13Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf13Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf13Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf1Entity.cs index 65eb4c13264..728acbde9d3 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf1Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf2Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf2Entity.cs index 6317348cacf..cdc56a8b5ac 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf2Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf2Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf3Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf3Entity.cs index cf660c08e83..bd66eec872a 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf3Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf3Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf3Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf4Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf4Entity.cs index 45da4074dda..d6936fcecce 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf4Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf4Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf4Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf5Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf5Entity.cs index 7bf9092f38b..a935c3c4511 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf5Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf5Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf5Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf6Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf6Entity.cs index 23bc9206daa..42e67eae384 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf6Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf6Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf6Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf7Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf7Entity.cs index 56b3412b673..a42e8b591ea 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf7Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf7Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf7Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf8Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf8Entity.cs index 9882306ff68..f01efbcf505 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf8Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf8Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf8Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf9Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf9Entity.cs index ad5590aad56..c2394e54b75 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf9Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.AnyOf9Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AnyOf9Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.cs index afc5e31fbd0..8ef289c5456 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.LibEntity.cs @@ -697,6 +697,12 @@ private void CheckValidInstance() public LibEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.cs index 4fd048fac54..6916240aa4a 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.LibEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct InstructsTheTypeScriptCompilerHowToCompileTsFiles public readonly partial struct LibEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public LibEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.MaxNodeModuleJsDepthEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.MaxNodeModuleJsDepthEntity.cs index ef30a5d020b..2f0025a4de5 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.MaxNodeModuleJsDepthEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.MaxNodeModuleJsDepthEntity.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public MaxNodeModuleJsDepthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf0Entity.cs index 3a4398796cf..0be45c5c8ce 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf0Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf1Entity.cs index a72438c4b06..39f39f3a07e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.AnyOf1Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.cs index 087dcfd78d0..d8dc657b450 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.cs @@ -384,6 +384,12 @@ private void CheckValidInstance() public ModuleResolutionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs index f1b8ef9f31c..cb4f65a535c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable.cs @@ -7660,6 +7660,366 @@ public bool RemoveWatchFile() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowJsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowJs(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowJsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowUmdGlobalAccessUtf8, out IJsonDocument? _, out int _)) + { + SetAllowUmdGlobalAccess(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.AllowAccessingUmdGlobalsFromModules.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CheckJsUtf8, out IJsonDocument? _, out int _)) + { + SetCheckJs(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingInTypeCheckedJavaScriptFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompositeUtf8, out IJsonDocument? _, out int _)) + { + SetComposite(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CompositeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeclarationUtf8, out IJsonDocument? _, out int _)) + { + SetDeclaration(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DeclarationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeclarationMapUtf8, out IJsonDocument? _, out int _)) + { + SetDeclarationMap(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourcemapsForDTsFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableSizeLimitUtf8, out IJsonDocument? _, out int _)) + { + SetDisableSizeLimit(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableSizeLimitEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DownlevelIterationUtf8, out IJsonDocument? _, out int _)) + { + SetDownlevelIteration(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DownlevelIterationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EmitBomUtf8, out IJsonDocument? _, out int _)) + { + SetEmitBom(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitBomEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EmitDeclarationOnlyUtf8, out IJsonDocument? _, out int _)) + { + SetEmitDeclarationOnly(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.OnlyOutputDTsFilesAndNotJavaScriptFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EsModuleInteropUtf8, out IJsonDocument? _, out int _)) + { + SetEsModuleInterop(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EsModuleInteropEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExactOptionalPropertyTypesUtf8, out IJsonDocument? _, out int _)) + { + SetExactOptionalPropertyTypes(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExactOptionalPropertyTypesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtendedDiagnosticsUtf8, out IJsonDocument? _, out int _)) + { + SetExtendedDiagnostics(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ExtendedDiagnosticsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ForceConsistentCasingInFileNamesUtf8, out IJsonDocument? _, out int _)) + { + SetForceConsistentCasingInFileNames(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnsureThatCasingIsCorrectInImports.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GenerateCpuProfileUtf8, out IJsonDocument? _, out int _)) + { + SetGenerateCpuProfile(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitAV8CpuProfileOfTheCompilerRunForDebugging.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImportHelpersUtf8, out IJsonDocument? _, out int _)) + { + SetImportHelpers(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportHelpersEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImportsNotUsedAsValuesUtf8, out IJsonDocument? _, out int _)) + { + SetImportsNotUsedAsValues(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ImportsNotUsedAsValuesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InlineSourceMapUtf8, out IJsonDocument? _, out int _)) + { + SetInlineSourceMap(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IncludeSourcemapFilesInsideTheEmittedJavaScript.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InlineSourcesUtf8, out IJsonDocument? _, out int _)) + { + SetInlineSources(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.InlineSourcesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsolatedModulesUtf8, out IJsonDocument? _, out int _)) + { + SetIsolatedModules(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.IsolatedModulesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsxFactoryUtf8, out IJsonDocument? _, out int _)) + { + SetJsxFactory(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFactoryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsxFragmentFactoryUtf8, out IJsonDocument? _, out int _)) + { + SetJsxFragmentFactory(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxFragmentFactoryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsxImportSourceUtf8, out IJsonDocument? _, out int _)) + { + SetJsxImportSource(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.JsxImportSourceEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.KeyofStringsOnlyUtf8, out IJsonDocument? _, out int _)) + { + SetKeyofStringsOnly(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.KeyofStringsOnlyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ListEmittedFilesUtf8, out IJsonDocument? _, out int _)) + { + SetListEmittedFiles(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintTheNamesOfEmittedFilesAfterACompilation.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ListFilesUtf8, out IJsonDocument? _, out int _)) + { + SetListFiles(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintAllOfTheFilesReadDuringTheCompilation.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxNodeModuleJsDepthUtf8, out IJsonDocument? _, out int _)) + { + SetMaxNodeModuleJsDepth(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.MaxNodeModuleJsDepthEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModuleResolutionUtf8, out IJsonDocument? _, out int _)) + { + SetModuleResolution(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ModuleResolutionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoEmitUtf8, out IJsonDocument? _, out int _)) + { + SetNoEmit(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingFileFromACompilation.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoEmitHelpersUtf8, out IJsonDocument? _, out int _)) + { + SetNoEmitHelpers(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitHelpersEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoEmitOnErrorUtf8, out IJsonDocument? _, out int _)) + { + SetNoEmitOnError(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitOnErrorEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoErrorTruncationUtf8, out IJsonDocument? _, out int _)) + { + SetNoErrorTruncation(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableTruncatingTypesInErrorMessages.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoFallthroughCasesInSwitchUtf8, out IJsonDocument? _, out int _)) + { + SetNoFallthroughCasesInSwitch(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitOverrideUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitOverride(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitReturnsUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitReturns(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoImplicitUseStrictUtf8, out IJsonDocument? _, out int _)) + { + SetNoImplicitUseStrict(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoLibUtf8, out IJsonDocument? _, out int _)) + { + SetNoLib(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoLibEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoResolveUtf8, out IJsonDocument? _, out int _)) + { + SetNoResolve(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoResolveEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoStrictGenericChecksUtf8, out IJsonDocument? _, out int _)) + { + SetNoStrictGenericChecks(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoUnusedLocalsUtf8, out IJsonDocument? _, out int _)) + { + SetNoUnusedLocals(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableErrorReportingWhenALocalVariablesArenTRead.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoUnusedParametersUtf8, out IJsonDocument? _, out int _)) + { + SetNoUnusedParameters(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PreserveConstEnumsUtf8, out IJsonDocument? _, out int _)) + { + SetPreserveConstEnums(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableErasingConstEnumDeclarationsInGeneratedCode.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PreserveSymlinksUtf8, out IJsonDocument? _, out int _)) + { + SetPreserveSymlinks(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveSymlinksEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PreserveValueImportsUtf8, out IJsonDocument? _, out int _)) + { + SetPreserveValueImports(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveValueImportsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrettyUtf8, out IJsonDocument? _, out int _)) + { + SetPretty(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrettyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReactNamespaceUtf8, out IJsonDocument? _, out int _)) + { + SetReactNamespace(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ReactNamespaceEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RemoveCommentsUtf8, out IJsonDocument? _, out int _)) + { + SetRemoveComments(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DisableEmittingComments.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResolveJsonModuleUtf8, out IJsonDocument? _, out int _)) + { + SetResolveJsonModule(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableImportingJsonFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResolvePackageJsonExportsUtf8, out IJsonDocument? _, out int _)) + { + SetResolvePackageJsonExports(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ResolvePackageJsonExportsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResolvePackageJsonImportsUtf8, out IJsonDocument? _, out int _)) + { + SetResolvePackageJsonImports(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.UseThePackageJsonImportsFieldWhenResolvingImports.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipDefaultLibCheckUtf8, out IJsonDocument? _, out int _)) + { + SetSkipDefaultLibCheck(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipDefaultLibCheckEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipLibCheckUtf8, out IJsonDocument? _, out int _)) + { + SetSkipLibCheck(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipTypeCheckingAllDTsFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SourceMapUtf8, out IJsonDocument? _, out int _)) + { + SetSourceMap(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.CreateSourceMapFilesForEmittedJavaScriptFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictUtf8, out IJsonDocument? _, out int _)) + { + SetStrict(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EnableAllStrictTypeCheckingOptions.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictBindCallApplyUtf8, out IJsonDocument? _, out int _)) + { + SetStrictBindCallApply(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictFunctionTypesUtf8, out IJsonDocument? _, out int _)) + { + SetStrictFunctionTypes(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictNullChecksUtf8, out IJsonDocument? _, out int _)) + { + SetStrictNullChecks(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictPropertyInitializationUtf8, out IJsonDocument? _, out int _)) + { + SetStrictPropertyInitialization(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuppressExcessPropertyErrorsUtf8, out IJsonDocument? _, out int _)) + { + SetSuppressExcessPropertyErrors(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SuppressImplicitAnyIndexErrorsUtf8, out IJsonDocument? _, out int _)) + { + SetSuppressImplicitAnyIndexErrors(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TargetUtf8, out IJsonDocument? _, out int _)) + { + SetTarget(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TraceResolutionUtf8, out IJsonDocument? _, out int _)) + { + SetTraceResolution(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TraceResolutionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TsBuildInfoFileUtf8, out IJsonDocument? _, out int _)) + { + SetTsBuildInfoFile(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TsBuildInfoFileEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseDefineForClassFieldsUtf8, out IJsonDocument? _, out int _)) + { + SetUseDefineForClassFields(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.EmitEcmaScriptStandardCompliantClassFields.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseUnknownInCatchVariablesUtf8, out IJsonDocument? _, out int _)) + { + SetUseUnknownInCatchVariables(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.DefaultCatchClauseVariablesAsUnknownInsteadOfAny.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchDirectoryUtf8, out IJsonDocument? _, out int _)) + { + SetWatchDirectory(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchDirectoryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchFileUtf8, out IJsonDocument? _, out int _)) + { + SetWatchFile(Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchFileEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitHelpersEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitHelpersEntity.cs index 579b1f8de5f..40f677693c7 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitHelpersEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitHelpersEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoEmitHelpersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitOnErrorEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitOnErrorEntity.cs index 3032abc1ba2..3d529ee65f9 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitOnErrorEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoEmitOnErrorEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoEmitOnErrorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs index 8e653402014..b502d8c9e8f 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoFallthroughCasesInSwitchEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoFallthroughCasesInSwitchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs index de9f847df5e..c99224dc1c9 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitOverrideEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoImplicitOverrideEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs index f13169f2922..99bb6fdf0fa 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitReturnsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoImplicitReturnsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs index edf2c401b96..38530bb1b02 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoImplicitUseStrictEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoImplicitUseStrictEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoLibEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoLibEntity.cs index 9478cb170fa..44db8af4d27 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoLibEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoLibEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoLibEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoResolveEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoResolveEntity.cs index fc6d2034b0e..d5f3fed31ac 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoResolveEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoResolveEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoResolveEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs index d6fc57337b1..681813f0417 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.NoStrictGenericChecksEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NoStrictGenericChecksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.OnlyOutputDTsFilesAndNotJavaScriptFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.OnlyOutputDTsFilesAndNotJavaScriptFiles.cs index bf3a38c6728..e80b8b1ebf9 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.OnlyOutputDTsFilesAndNotJavaScriptFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.OnlyOutputDTsFilesAndNotJavaScriptFiles.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public OnlyOutputDTsFilesAndNotJavaScriptFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.JsonStringArray.cs index 244ba0a5b16..b27ae51ef9f 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct PathsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.cs index 24a3359d691..594e180a33e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PathsEntity.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public PathsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.Mutable.cs index fe92c9a96cf..e5b087d63c0 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.Mutable.cs @@ -284,6 +284,31 @@ public bool RemoveName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.cs index 6d4fea0c941..eb96a0e9fa6 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.PluginsEntity.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public PluginsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.cs index 7694ae3ef3e..72f12940fa3 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PluginsEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct InstructsTheTypeScriptCompilerHowToCompileTsFiles public readonly partial struct PluginsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public PluginsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveSymlinksEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveSymlinksEntity.cs index c3ad60f0b52..50416fa3c26 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveSymlinksEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveSymlinksEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public PreserveSymlinksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveValueImportsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveValueImportsEntity.cs index 964feb5877d..79a3c670dfe 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveValueImportsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PreserveValueImportsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public PreserveValueImportsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrettyEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrettyEntity.cs index 0f5bcefc4fb..42ec7fcb76e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrettyEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrettyEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public PrettyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintAllOfTheFilesReadDuringTheCompilation.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintAllOfTheFilesReadDuringTheCompilation.cs index c06fc477868..b8b3ba56698 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintAllOfTheFilesReadDuringTheCompilation.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintAllOfTheFilesReadDuringTheCompilation.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public PrintAllOfTheFilesReadDuringTheCompilation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintTheNamesOfEmittedFilesAfterACompilation.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintTheNamesOfEmittedFilesAfterACompilation.cs index cfc43fe183a..72e404a3669 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintTheNamesOfEmittedFilesAfterACompilation.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.PrintTheNamesOfEmittedFilesAfterACompilation.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public PrintTheNamesOfEmittedFilesAfterACompilation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs index 98e27449a02..addb1e7c219 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RaiseAnErrorWhenAFunctionParameterIsnTRead.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public RaiseAnErrorWhenAFunctionParameterIsnTRead Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ReactNamespaceEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ReactNamespaceEntity.cs index 3d91ef10059..6337c0b8500 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ReactNamespaceEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ReactNamespaceEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public ReactNamespaceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ResolvePackageJsonExportsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ResolvePackageJsonExportsEntity.cs index c11e6fba219..793565227d5 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ResolvePackageJsonExportsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.ResolvePackageJsonExportsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ResolvePackageJsonExportsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RootDirsJsArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RootDirsJsArray.cs index a6df51f781d..c08e6a7e2f7 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RootDirsJsArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.RootDirsJsArray.cs @@ -30,11 +30,13 @@ public readonly partial struct InstructsTheTypeScriptCompilerHowToCompileTsFiles public readonly partial struct RootDirsJsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RootDirsJsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf0Entity.cs index 863fcab3579..d5d02c4a3a2 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf0Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf1Entity.cs index f46ef429fd0..7911e876dab 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.AnyOf1Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.cs index 65cd136755e..6b0ad4742b1 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SetTheNewlineCharacterForEmittingFiles.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public SetTheNewlineCharacterForEmittingFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipDefaultLibCheckEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipDefaultLibCheckEntity.cs index 8b6a7da7c68..ac236bc88f4 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipDefaultLibCheckEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipDefaultLibCheckEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SkipDefaultLibCheckEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipTypeCheckingAllDTsFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipTypeCheckingAllDTsFiles.cs index 9a276bf7d5c..f5aa5e78c9e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipTypeCheckingAllDTsFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SkipTypeCheckingAllDTsFiles.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SkipTypeCheckingAllDTsFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyMulArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyMulArray.cs index fa1b6ab2c31..1926875157e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyMulArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyMulArray.cs @@ -30,11 +30,13 @@ public readonly partial struct InstructsTheTypeScriptCompilerHowToCompileTsFiles public readonly partial struct SpecifyMulArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public SpecifyMulArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyTheOutputDirectoryForGeneratedDeclarationFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyTheOutputDirectoryForGeneratedDeclarationFiles.cs index a12bff4be72..be5869bb7fa 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyTheOutputDirectoryForGeneratedDeclarationFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyTheOutputDirectoryForGeneratedDeclarationFiles.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public SpecifyTheOutputDirectoryForGeneratedDeclarationFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs index 576944a7304..7e043f3905c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatJsxCodeIsGenerated.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public SpecifyWhatJsxCodeIsGenerated Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf0Entity.cs index a826714bfec..8b44bde8bc8 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf0Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf1Entity.cs index 105e38f4695..4eebf4a2a5b 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.AnyOf1Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.cs index 420a3d177cb..31ebebf4b5b 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SpecifyWhatModuleCodeIsGenerated.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public SpecifyWhatModuleCodeIsGenerated Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs index f7ef93f60c8..04479a444d1 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictBindCallApplyEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public StrictBindCallApplyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs index ef136f37e9b..b891927d640 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictFunctionTypesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public StrictFunctionTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs index 1aae064b270..c80d24d82f1 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.StrictPropertyInitializationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public StrictPropertyInitializationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs index a35eb1ac85c..b50ff037981 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressExcessPropertyErrorsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SuppressExcessPropertyErrorsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs index e6b52d0f388..2d57f028153 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.SuppressImplicitAnyIndexErrorsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SuppressImplicitAnyIndexErrorsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf0Entity.cs index c3affbd6c0a..b4408830b47 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf0Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf1Entity.cs index d472ede49bb..36cafd8657e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.AnyOf1Entity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.cs index 332401f34fe..753c65ee1db 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TargetEntity.cs @@ -384,6 +384,12 @@ private void CheckValidInstance() public TargetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TraceResolutionEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TraceResolutionEntity.cs index e24b93e1db1..2374d083d42 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TraceResolutionEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TraceResolutionEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public TraceResolutionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TsBuildInfoFileEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TsBuildInfoFileEntity.cs index b727d3cc726..9e6f42c4ed2 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TsBuildInfoFileEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TsBuildInfoFileEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TsBuildInfoFileEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TypesJsonSArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TypesJsonSArray.cs index 3c13402a16b..555cee8db34 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TypesJsonSArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.TypesJsonSArray.cs @@ -30,11 +30,13 @@ public readonly partial struct InstructsTheTypeScriptCompilerHowToCompileTsFiles public readonly partial struct TypesJsonSArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public TypesJsonSArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.UseThePackageJsonImportsFieldWhenResolvingImports.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.UseThePackageJsonImportsFieldWhenResolvingImports.cs index 776dbd8c733..fdedd265d03 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.UseThePackageJsonImportsFieldWhenResolvingImports.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.UseThePackageJsonImportsFieldWhenResolvingImports.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public UseThePackageJsonImportsFieldWhenResolvingImports Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchDirectoryEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchDirectoryEntity.cs index 4de3195e2ac..cfb33268fcc 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchDirectoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchDirectoryEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public WatchDirectoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchFileEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchFileEntity.cs index 62ff7023bcf..0de344c0e06 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchFileEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WatchFileEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public WatchFileEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs index 31abd97ac22..b68db987178 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.WhenTypeCheckingTakeIntoAccountNullAndUndefined.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WhenTypeCheckingTakeIntoAccountNullAndUndefined Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs index f754a841f77..6a391a19734 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.cs @@ -2635,6 +2635,12 @@ private void CheckValidInstance() public InstructsTheTypeScriptCompilerHowToCompileTsFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.Mutable.cs index 2005d7674f5..4d315882ed9 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.Mutable.cs @@ -314,6 +314,37 @@ public bool RemoveCompilerOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompilerOptionsUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable __corvusCompilerOptions)) + { + __corvusCompilerOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.cs index 9ed06d646b7..7ec8c519c9e 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.CompilerOptionsDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public CompilerOptionsDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.JsonStringArray.cs index 71d56c26abf..c8565ca2f43 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ExcludeDefinition public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.Mutable.cs index 66f83a35b34..25a3144cd1f 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.Mutable.cs @@ -314,6 +314,31 @@ public bool RemoveExclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.cs index fe4bde4a30a..de3a1d8935c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExcludeDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public ExcludeDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.JsonStringArray.cs index 8da142d6ebd..fea4a596c69 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.JsonStringArray.cs @@ -35,11 +35,13 @@ public readonly partial struct ExtendsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.OneOf0Entity.cs index 7c1c0b85aef..08359cb8df2 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.cs index 3db4cc6209d..9e55bb1f8ed 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.ExtendsEntity.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public ExtendsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.Mutable.cs index d3643bdbc9e..bf9c85efa21 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.Mutable.cs @@ -314,6 +314,31 @@ public bool RemoveExtends() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.cs index 15b23a8baab..cf2b9b2c768 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ExtendsDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public ExtendsDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.JsonStringArray.cs index 42fb657af58..7645cd676b0 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct FilesDefinition public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.Mutable.cs index cab6f870059..2ade6e3307c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.Mutable.cs @@ -314,6 +314,31 @@ public bool RemoveFiles() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.cs index 1f677c61ed1..b9874e6b593 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.FilesDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public FilesDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.JsonStringArray.cs index 5bfd149990b..d4a8ec16484 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct IncludeDefinition public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.Mutable.cs index a59d3c01299..0ff0571d706 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.Mutable.cs @@ -314,6 +314,31 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.cs index 89541d8cd7b..74544266a87 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.IncludeDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public IncludeDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.Mutable.cs index 59fecc44e08..d822541cff7 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.Mutable.cs @@ -978,6 +978,55 @@ public bool RemoveWatchOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuildOptionsUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.BuildOptionsDefinition.BuildOptionsEntity.Mutable __corvusBuildOptions)) + { + __corvusBuildOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompilerOptionsUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.CompilerOptionsDefinition.InstructsTheTypeScriptCompilerHowToCompileTsFiles.Mutable __corvusCompilerOptions)) + { + __corvusCompilerOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypeAcquisitionUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.Mutable __corvusTypeAcquisition)) + { + __corvusTypeAcquisition.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchOptionsUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.Mutable __corvusWatchOptions)) + { + __corvusWatchOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.Mutable.cs index 8fbb887e51b..25000d4aabb 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.Mutable.cs @@ -314,6 +314,31 @@ public bool RemoveReferences() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.Mutable.cs index bb79b373d4b..afe0cace316 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.Mutable.cs @@ -282,6 +282,31 @@ public bool RemovePath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.cs index 3be502fcae3..3123a9d9e60 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.ProjectReference.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ProjectReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.cs index 11440e54916..4814cb81ca5 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.ProjectReferenceArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ReferencesDefinition public readonly partial struct ProjectReferenceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ProjectReferenceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.cs index 08ff91dd58d..2078b6f0bed 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.ReferencesDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public ReferencesDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.Mutable.cs index ca2da9629a0..a28a7c14832 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.Mutable.cs @@ -314,6 +314,37 @@ public bool RemoveTypeAcquisition() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypeAcquisitionUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.Mutable __corvusTypeAcquisition)) + { + __corvusTypeAcquisition.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.EnableAutoTypeAcquisition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.EnableAutoTypeAcquisition.cs index 0d28f2824b2..bbc6f794b6b 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.EnableAutoTypeAcquisition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.EnableAutoTypeAcquisition.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EnableAutoTypeAcquisition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.IncludeJsoArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.IncludeJsoArray.cs index 275e9e152d3..8709a3abe32 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.IncludeJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.IncludeJsoArray.cs @@ -30,11 +30,13 @@ public readonly partial struct TypeAcquisitionEntity public readonly partial struct IncludeJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public IncludeJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.JsonStringArray.cs index 3221cbfbbbc..c20c1613850 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct TypeAcquisitionEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.Mutable.cs index 2c84451a3e3..ec855c609c6 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.Mutable.cs @@ -484,6 +484,36 @@ public bool RemoveInclude() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableUtf8, out IJsonDocument? _, out int _)) + { + SetEnable(Corvus.JsconfigBenchmark.Current.JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.EnableAutoTypeAcquisition.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.cs index 952e55eea28..13755042913 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.TypeAcquisitionEntity.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public TypeAcquisitionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.cs index 423e47630ee..ebcd5bf69b0 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.TypeAcquisitionDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public TypeAcquisitionDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.Mutable.cs index dde2d20d5d0..a57acbfa5c2 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.Mutable.cs @@ -314,6 +314,37 @@ public bool RemoveWatchOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchOptionsUtf8, out Corvus.JsconfigBenchmark.Current.JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.Mutable __corvusWatchOptions)) + { + __corvusWatchOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.JsonStringArray.cs index 7b8874edd28..185c9a4cb73 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct SettingsForTheWatchModeInTypeScript public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.Mutable.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.Mutable.cs index 99a11ab0de9..68a59eb900c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.Mutable.cs @@ -748,6 +748,31 @@ public bool RemoveWatchFile() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.RemoveALisArray.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.RemoveALisArray.cs index 8e1bcd0592d..c6d92390fe1 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.RemoveALisArray.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.RemoveALisArray.cs @@ -30,11 +30,13 @@ public readonly partial struct SettingsForTheWatchModeInTypeScript public readonly partial struct RemoveALisArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RemoveALisArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.cs index ae0d3aa3277..fccf1cdae1c 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.SettingsForTheWatchModeInTypeScript.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public SettingsForTheWatchModeInTypeScript Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.cs index d70e60a10f1..e10fa2bcbf8 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.WatchOptionsDefinition.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public WatchOptionsDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.cs index 0acdfcc8130..10929fc94e9 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsconfigSchema.cs @@ -655,6 +655,12 @@ private void CheckValidInstance() public JsconfigSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonBoolean.cs index a027b91986e..1e4cde28475 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonString.cs index d83ff9f60f1..458d5aacb6f 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/corvusjson-jsonschema.lock index 09c58e7d2c0..fa633febe9d 100644 --- a/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.JsconfigBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:33.8717330\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:13.7549339\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.BossEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.BossEntity.cs index 9b5d28192f1..f8ab1f00c4a 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.BossEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.BossEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public BossEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.CurlyEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.CurlyEntity.cs index 43b61fa6740..e6ce627bfa8 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.CurlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.CurlyEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public CurlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.DebugEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.DebugEntity.cs index 5c4ef604434..88f7e5870f6 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.DebugEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.DebugEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public DebugEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ElisionEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ElisionEntity.cs index 1f191a9b657..001e9f72d4c 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ElisionEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ElisionEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ElisionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentBrowserify.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentBrowserify.cs index 65dbc0f541b..98feaa94f88 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentBrowserify.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentBrowserify.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentBrowserify Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentCouchDb.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentCouchDb.cs index d7b8e3c4afb..be9c0d78da8 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentCouchDb.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentCouchDb.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentCouchDb Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsExposedByTheShellJsLibrary.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsExposedByTheShellJsLibrary.cs index 2c2cb77ee7a..4561076965c 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsExposedByTheShellJsLibrary.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsExposedByTheShellJsLibrary.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentDefinesGlobalsExposedByTheShellJsLibrary Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsForTypedArrayConstructors.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsForTypedArrayConstructors.cs index dc6550c0673..32723673438 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsForTypedArrayConstructors.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDefinesGlobalsForTypedArrayConstructors.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentDefinesGlobalsForTypedArrayConstructors Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDevelopmentDebuggingAlertConfirmEtc.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDevelopmentDebuggingAlertConfirmEtc.cs index 7417ec8a809..9a59fa25aee 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDevelopmentDebuggingAlertConfirmEtc.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDevelopmentDebuggingAlertConfirmEtc.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentDevelopmentDebuggingAlertConfirmEtc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDojoToolkit.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDojoToolkit.cs index 4071ab8fc06..de77ebef90a 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDojoToolkit.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentDojoToolkit.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentDojoToolkit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentEs6Module.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentEs6Module.cs index 096b264590d..372fd36c95c 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentEs6Module.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentEs6Module.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentEs6Module Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJQuery.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJQuery.cs index 87b6eae9e93..4bc211380ba 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJQuery.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJQuery.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentJQuery Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJasmineUnitTestingFramework.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJasmineUnitTestingFramework.cs index 9fa415cbbed..1cc50f2391b 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJasmineUnitTestingFramework.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentJasmineUnitTestingFramework.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentJasmineUnitTestingFramework Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMochaUnitTestingFramework.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMochaUnitTestingFramework.cs index c2fc6624d8b..aa5ad33569e 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMochaUnitTestingFramework.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMochaUnitTestingFramework.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentMochaUnitTestingFramework Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMooTools.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMooTools.cs index ec18a4bab14..90f52e7066e 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMooTools.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentMooTools.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentMooTools Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentNodeJs.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentNodeJs.cs index 7e2cd7e9d38..8cd09bfd6d7 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentNodeJs.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentNodeJs.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentNodeJs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPhantomJsRuntimeEnvironment.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPhantomJsRuntimeEnvironment.cs index e9355af52f4..8b2d8109785 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPhantomJsRuntimeEnvironment.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPhantomJsRuntimeEnvironment.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentPhantomJsRuntimeEnvironment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPrototypeJavaScriptFramework.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPrototypeJavaScriptFramework.cs index 60759d783dd..f7b23df74cf 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPrototypeJavaScriptFramework.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentPrototypeJavaScriptFramework.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentPrototypeJavaScriptFramework Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentRhino.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentRhino.cs index 7921430f08f..a5887c33505 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentRhino.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentRhino.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentRhino Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebBrowserWindowDocumentEtc.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebBrowserWindowDocumentEtc.cs index 05075fb8282..fe3e799ec5e 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebBrowserWindowDocumentEtc.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebBrowserWindowDocumentEtc.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentWebBrowserWindowDocumentEtc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebWorkers.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebWorkers.cs index 08fafcd6cca..e6b7cd0b447 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebWorkers.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWebWorkers.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentWebWorkers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWidelyAdoptedGlobalsEscapeUnescapeEtc.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWidelyAdoptedGlobalsEscapeUnescapeEtc.cs index 4b087ac052e..6f301c58549 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWidelyAdoptedGlobalsEscapeUnescapeEtc.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWidelyAdoptedGlobalsEscapeUnescapeEtc.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentWidelyAdoptedGlobalsEscapeUnescapeEtc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWindowsScriptingHost.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWindowsScriptingHost.cs index 43eec9212ef..b43ebb54f7e 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWindowsScriptingHost.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentWindowsScriptingHost.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentWindowsScriptingHost Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentYahooUserInterface.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentYahooUserInterface.cs index 33bf18089b1..19cff8381ed 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentYahooUserInterface.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.EnvironmentYahooUserInterface.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EnvironmentYahooUserInterface Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ExprEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ExprEntity.cs index 40aa448488d..ddc1649b2f8 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ExprEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ExprEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ExprEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ForinEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ForinEntity.cs index 9ca06d29d6a..dda71198376 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ForinEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ForinEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ForinEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FreezeEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FreezeEntity.cs index c64b0db6534..e9317868cd9 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FreezeEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FreezeEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public FreezeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuncscopeEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuncscopeEntity.cs index 236f834f0d3..f90cb5a4312 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuncscopeEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuncscopeEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public FuncscopeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuturehostileEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuturehostileEntity.cs index 494dde1a6b6..7538131a303 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuturehostileEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.FuturehostileEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public FuturehostileEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.GlobalsEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.GlobalsEntity.cs index 5e5ba625c87..a9a274e4000 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.GlobalsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.GlobalsEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public GlobalsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.LastsemicEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.LastsemicEntity.cs index 46c4da3d11f..4313f794a6e 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.LastsemicEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.LastsemicEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public LastsemicEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxCyclomaticComplexityPerFunction.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxCyclomaticComplexityPerFunction.cs index 8457d0981b3..4ac5e72ff50 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxCyclomaticComplexityPerFunction.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxCyclomaticComplexityPerFunction.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public MaxCyclomaticComplexityPerFunction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxDepthOfNestedBlocks.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxDepthOfNestedBlocks.cs index 0c10b13c559..e5a424f314d 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxDepthOfNestedBlocks.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxDepthOfNestedBlocks.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public MaxDepthOfNestedBlocks Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberOfFormalParametersAllowedPerFunction.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberOfFormalParametersAllowedPerFunction.cs index 9753ef75554..c9b2950b690 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberOfFormalParametersAllowedPerFunction.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberOfFormalParametersAllowedPerFunction.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public MaxNumberOfFormalParametersAllowedPerFunction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberStatementsPerFunction.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberStatementsPerFunction.cs index bd03698921c..9531a5a8a5b 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberStatementsPerFunction.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaxNumberStatementsPerFunction.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public MaxNumberStatementsPerFunction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaximumAmountOfWarningsJsHintWillProduceBeforeGivingUp.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaximumAmountOfWarningsJsHintWillProduceBeforeGivingUp.cs index 061c21a2718..55f9e87354a 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaximumAmountOfWarningsJsHintWillProduceBeforeGivingUp.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.MaximumAmountOfWarningsJsHintWillProduceBeforeGivingUp.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public MaximumAmountOfWarningsJsHintWillProduceBeforeGivingUp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.Mutable.cs index 1d7dbde8c0b..e6edb6c6438 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.Mutable.cs @@ -4901,6 +4901,361 @@ public bool RemoveYui() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsiUtf8, out IJsonDocument? _, out int _)) + { + SetAsi(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutMissingSemicolons.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BitwiseUtf8, out IJsonDocument? _, out int _)) + { + SetBitwise(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitTheUseOfBitwiseOperatorsEtc.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BossUtf8, out IJsonDocument? _, out int _)) + { + SetBoss(Corvus.JshintrcBenchmark.Current.JshintrcSchema.BossEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BrowserUtf8, out IJsonDocument? _, out int _)) + { + SetBrowser(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentWebBrowserWindowDocumentEtc.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BrowserifyUtf8, out IJsonDocument? _, out int _)) + { + SetBrowserify(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentBrowserify.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CouchUtf8, out IJsonDocument? _, out int _)) + { + SetCouch(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentCouchDb.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CurlyUtf8, out IJsonDocument? _, out int _)) + { + SetCurly(Corvus.JshintrcBenchmark.Current.JshintrcSchema.CurlyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.JshintrcBenchmark.Current.JshintrcSchema.DebugEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DevelUtf8, out IJsonDocument? _, out int _)) + { + SetDevel(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentDevelopmentDebuggingAlertConfirmEtc.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DojoUtf8, out IJsonDocument? _, out int _)) + { + SetDojo(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentDojoToolkit.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElisionUtf8, out IJsonDocument? _, out int _)) + { + SetElision(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ElisionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EqeqeqUtf8, out IJsonDocument? _, out int _)) + { + SetEqeqeq(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitsTheUseOfAndInFavorOfAnd.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EqnullUtf8, out IJsonDocument? _, out int _)) + { + SetEqnull(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutNullComparisons.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EsversionUtf8, out IJsonDocument? _, out int _)) + { + SetEsversion(Corvus.JshintrcBenchmark.Current.JshintrcSchema.TheEcmaScriptVersionToWhichTheCodeMustAdhere.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EvilUtf8, out IJsonDocument? _, out int _)) + { + SetEvil(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutTheUseOfEval.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExprUtf8, out IJsonDocument? _, out int _)) + { + SetExpr(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ExprEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ForinUtf8, out IJsonDocument? _, out int _)) + { + SetForin(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ForinEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FreezeValueUtf8, out IJsonDocument? _, out int _)) + { + SetFreezeValue(Corvus.JshintrcBenchmark.Current.JshintrcSchema.FreezeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FuncscopeUtf8, out IJsonDocument? _, out int _)) + { + SetFuncscope(Corvus.JshintrcBenchmark.Current.JshintrcSchema.FuncscopeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FuturehostileUtf8, out IJsonDocument? _, out int _)) + { + SetFuturehostile(Corvus.JshintrcBenchmark.Current.JshintrcSchema.FuturehostileEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IteratorUtf8, out IJsonDocument? _, out int _)) + { + SetIterator(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutTheIteratorProperty.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JasmineUtf8, out IJsonDocument? _, out int _)) + { + SetJasmine(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentJasmineUnitTestingFramework.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JqueryUtf8, out IJsonDocument? _, out int _)) + { + SetJquery(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentJQuery.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LastsemicUtf8, out IJsonDocument? _, out int _)) + { + SetLastsemic(Corvus.JshintrcBenchmark.Current.JshintrcSchema.LastsemicEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LatedefUtf8, out IJsonDocument? _, out int _)) + { + SetLatedef(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitsTheUseOfAVariableBeforeItWasDefined.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LeanswitchUtf8, out IJsonDocument? _, out int _)) + { + SetLeanswitch(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitsUnnecessaryClausesWithinSwitchStatements.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LoopfuncUtf8, out IJsonDocument? _, out int _)) + { + SetLoopfunc(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutFunctionsInsideOfLoops.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxcomplexityUtf8, out IJsonDocument? _, out int _)) + { + SetMaxcomplexity(Corvus.JshintrcBenchmark.Current.JshintrcSchema.MaxCyclomaticComplexityPerFunction.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxdepthUtf8, out IJsonDocument? _, out int _)) + { + SetMaxdepth(Corvus.JshintrcBenchmark.Current.JshintrcSchema.MaxDepthOfNestedBlocks.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxerrUtf8, out IJsonDocument? _, out int _)) + { + SetMaxerr(Corvus.JshintrcBenchmark.Current.JshintrcSchema.MaximumAmountOfWarningsJsHintWillProduceBeforeGivingUp.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxstatementsUtf8, out IJsonDocument? _, out int _)) + { + SetMaxstatements(Corvus.JshintrcBenchmark.Current.JshintrcSchema.MaxNumberStatementsPerFunction.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MochaUtf8, out IJsonDocument? _, out int _)) + { + SetMocha(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentMochaUnitTestingFramework.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModuleUtf8, out IJsonDocument? _, out int _)) + { + SetModule(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentEs6Module.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MootoolsUtf8, out IJsonDocument? _, out int _)) + { + SetMootools(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentMooTools.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MozUtf8, out IJsonDocument? _, out int _)) + { + SetMoz(Corvus.JshintrcBenchmark.Current.JshintrcSchema.TellsJsHintThatYourCodeUsesMozillaJavaScriptExtensions.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoargUtf8, out IJsonDocument? _, out int _)) + { + SetNoarg(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitsTheUseOfArgumentsCallerAndArgumentsCallee.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NocommaUtf8, out IJsonDocument? _, out int _)) + { + SetNocomma(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitsTheUseOfTheCommaOperator.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NodeUtf8, out IJsonDocument? _, out int _)) + { + SetNode(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentNodeJs.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NonbspUtf8, out IJsonDocument? _, out int _)) + { + SetNonbsp(Corvus.JshintrcBenchmark.Current.JshintrcSchema.WarnsAboutNonBreakingWhitespaceCharacters.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NonewUtf8, out IJsonDocument? _, out int _)) + { + SetNonew(Corvus.JshintrcBenchmark.Current.JshintrcSchema.NonewEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NonstandardUtf8, out IJsonDocument? _, out int _)) + { + SetNonstandard(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentWidelyAdoptedGlobalsEscapeUnescapeEtc.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoreturnawaitUtf8, out IJsonDocument? _, out int _)) + { + SetNoreturnawait(Corvus.JshintrcBenchmark.Current.JshintrcSchema.NoreturnawaitEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NotypeofUtf8, out IJsonDocument? _, out int _)) + { + SetNotypeof(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutInvalidTypeofOperatorValues.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoyieldUtf8, out IJsonDocument? _, out int _)) + { + SetNoyield(Corvus.JshintrcBenchmark.Current.JshintrcSchema.NoyieldEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PhantomUtf8, out IJsonDocument? _, out int _)) + { + SetPhantom(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentPhantomJsRuntimeEnvironment.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PlusplusUtf8, out IJsonDocument? _, out int _)) + { + SetPlusplus(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitsTheUseOfAnd.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProtoUtf8, out IJsonDocument? _, out int _)) + { + SetProto(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutTheProtoProperty.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrototypejsUtf8, out IJsonDocument? _, out int _)) + { + SetPrototypejs(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentPrototypeJavaScriptFramework.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RegexpuUtf8, out IJsonDocument? _, out int _)) + { + SetRegexpu(Corvus.JshintrcBenchmark.Current.JshintrcSchema.RegexpuEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RhinoUtf8, out IJsonDocument? _, out int _)) + { + SetRhino(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentRhino.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScripturlUtf8, out IJsonDocument? _, out int _)) + { + SetScripturl(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutTheUseOfScriptTargetedUrLs.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShadowUtf8, out IJsonDocument? _, out int _)) + { + SetShadow(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ShadowEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShelljsUtf8, out IJsonDocument? _, out int _)) + { + SetShelljs(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentDefinesGlobalsExposedByTheShellJsLibrary.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SingleGroupsUtf8, out IJsonDocument? _, out int _)) + { + SetSingleGroups(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SingleGroupsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrictUtf8, out IJsonDocument? _, out int _)) + { + SetStrict(Corvus.JshintrcBenchmark.Current.JshintrcSchema.RequiresAllCodeToRunInEs5StrictMode.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SupernewUtf8, out IJsonDocument? _, out int _)) + { + SetSupernew(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SupernewEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TrailingcommaUtf8, out IJsonDocument? _, out int _)) + { + SetTrailingcomma(Corvus.JshintrcBenchmark.Current.JshintrcSchema.TrailingcommaEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypedUtf8, out IJsonDocument? _, out int _)) + { + SetTyped(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentDefinesGlobalsForTypedArrayConstructors.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UndefUtf8, out IJsonDocument? _, out int _)) + { + SetUndef(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ProhibitsTheUseOfExplicitlyUndeclaredVariables.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UnusedUtf8, out IJsonDocument? _, out int _)) + { + SetUnused(Corvus.JshintrcBenchmark.Current.JshintrcSchema.WarnsWhenYouDefineAndNeverUseYourVariables.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValidthisUtf8, out IJsonDocument? _, out int _)) + { + SetValidthis(Corvus.JshintrcBenchmark.Current.JshintrcSchema.ValidthisEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VarstmtUtf8, out IJsonDocument? _, out int _)) + { + SetVarstmt(Corvus.JshintrcBenchmark.Current.JshintrcSchema.VarstmtEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WithstmtUtf8, out IJsonDocument? _, out int _)) + { + SetWithstmt(Corvus.JshintrcBenchmark.Current.JshintrcSchema.SuppressesWarningsAboutTheUseOfTheWithStatement.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WorkerUtf8, out IJsonDocument? _, out int _)) + { + SetWorker(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentWebWorkers.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WshUtf8, out IJsonDocument? _, out int _)) + { + SetWsh(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentWindowsScriptingHost.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.YuiUtf8, out IJsonDocument? _, out int _)) + { + SetYui(Corvus.JshintrcBenchmark.Current.JshintrcSchema.EnvironmentYahooUserInterface.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NonewEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NonewEntity.cs index 643795c0028..c237f0e85c8 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NonewEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NonewEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public NonewEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoreturnawaitEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoreturnawaitEntity.cs index c72362ce975..128843d7478 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoreturnawaitEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoreturnawaitEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public NoreturnawaitEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoyieldEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoyieldEntity.cs index 160bae9da7b..fe6aa173d3e 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoyieldEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.NoyieldEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public NoyieldEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.OverridesEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.OverridesEntity.cs index 694fe67351f..3a50b5724f5 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.OverridesEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.OverridesEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public OverridesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitTheUseOfBitwiseOperatorsEtc.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitTheUseOfBitwiseOperatorsEtc.cs index a7a25da6001..ba044608b59 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitTheUseOfBitwiseOperatorsEtc.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitTheUseOfBitwiseOperatorsEtc.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ProhibitTheUseOfBitwiseOperatorsEtc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAVariableBeforeItWasDefined.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAVariableBeforeItWasDefined.cs index 9b503944b17..4deac49dd0a 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAVariableBeforeItWasDefined.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAVariableBeforeItWasDefined.cs @@ -368,6 +368,12 @@ private void CheckValidInstance() public ProhibitsTheUseOfAVariableBeforeItWasDefined Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAnd.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAnd.cs index b4045021094..f1642343dba 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAnd.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAnd.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ProhibitsTheUseOfAnd Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAndInFavorOfAnd.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAndInFavorOfAnd.cs index 7c45396f19b..73adccf3626 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAndInFavorOfAnd.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfAndInFavorOfAnd.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ProhibitsTheUseOfAndInFavorOfAnd Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfArgumentsCallerAndArgumentsCallee.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfArgumentsCallerAndArgumentsCallee.cs index 11c3a1bc015..ddff2008705 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfArgumentsCallerAndArgumentsCallee.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfArgumentsCallerAndArgumentsCallee.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ProhibitsTheUseOfArgumentsCallerAndArgumentsCallee Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfExplicitlyUndeclaredVariables.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfExplicitlyUndeclaredVariables.cs index 677ac341611..7a54615f526 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfExplicitlyUndeclaredVariables.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfExplicitlyUndeclaredVariables.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ProhibitsTheUseOfExplicitlyUndeclaredVariables Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfTheCommaOperator.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfTheCommaOperator.cs index 8074d9fed11..e069317faa3 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfTheCommaOperator.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsTheUseOfTheCommaOperator.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ProhibitsTheUseOfTheCommaOperator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsUnnecessaryClausesWithinSwitchStatements.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsUnnecessaryClausesWithinSwitchStatements.cs index 83ba6ac6acb..073ca4803a1 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsUnnecessaryClausesWithinSwitchStatements.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ProhibitsUnnecessaryClausesWithinSwitchStatements.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ProhibitsUnnecessaryClausesWithinSwitchStatements Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RegexpuEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RegexpuEntity.cs index 0b54e8b7202..9b5957fa4db 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RegexpuEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RegexpuEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public RegexpuEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RequiresAllCodeToRunInEs5StrictMode.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RequiresAllCodeToRunInEs5StrictMode.cs index ca71d204978..209aab2b19b 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RequiresAllCodeToRunInEs5StrictMode.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.RequiresAllCodeToRunInEs5StrictMode.cs @@ -368,6 +368,12 @@ private void CheckValidInstance() public RequiresAllCodeToRunInEs5StrictMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ShadowEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ShadowEntity.cs index 688e35b4f48..5bbd9d88af4 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ShadowEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ShadowEntity.cs @@ -368,6 +368,12 @@ private void CheckValidInstance() public ShadowEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SingleGroupsEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SingleGroupsEntity.cs index ad332ad764a..d910769efb8 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SingleGroupsEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SingleGroupsEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SingleGroupsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SupernewEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SupernewEntity.cs index df093456788..ad2b75912a7 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SupernewEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SupernewEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SupernewEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutFunctionsInsideOfLoops.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutFunctionsInsideOfLoops.cs index d162c57ef67..bd39a208164 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutFunctionsInsideOfLoops.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutFunctionsInsideOfLoops.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutFunctionsInsideOfLoops Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutInvalidTypeofOperatorValues.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutInvalidTypeofOperatorValues.cs index f2ef1f981c4..91e9ccfa815 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutInvalidTypeofOperatorValues.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutInvalidTypeofOperatorValues.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutInvalidTypeofOperatorValues Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutMissingSemicolons.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutMissingSemicolons.cs index 5bc44a62fa4..c52514f6218 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutMissingSemicolons.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutMissingSemicolons.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutMissingSemicolons Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutNullComparisons.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutNullComparisons.cs index 71ba6934210..face193c4a2 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutNullComparisons.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutNullComparisons.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutNullComparisons Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheIteratorProperty.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheIteratorProperty.cs index db3e56b0e80..37ec047c9cb 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheIteratorProperty.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheIteratorProperty.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutTheIteratorProperty Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheProtoProperty.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheProtoProperty.cs index 19e19a04697..76fa4f3bc51 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheProtoProperty.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheProtoProperty.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutTheProtoProperty Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfEval.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfEval.cs index 7d4c32ffbda..1559afab74c 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfEval.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfEval.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutTheUseOfEval Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfScriptTargetedUrLs.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfScriptTargetedUrLs.cs index 722445851d8..036e32cf7d1 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfScriptTargetedUrLs.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfScriptTargetedUrLs.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutTheUseOfScriptTargetedUrLs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfTheWithStatement.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfTheWithStatement.cs index 97128f7538f..a705735d00f 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfTheWithStatement.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.SuppressesWarningsAboutTheUseOfTheWithStatement.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SuppressesWarningsAboutTheUseOfTheWithStatement Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TellsJsHintThatYourCodeUsesMozillaJavaScriptExtensions.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TellsJsHintThatYourCodeUsesMozillaJavaScriptExtensions.cs index 4ceddf81d36..b222c052129 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TellsJsHintThatYourCodeUsesMozillaJavaScriptExtensions.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TellsJsHintThatYourCodeUsesMozillaJavaScriptExtensions.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public TellsJsHintThatYourCodeUsesMozillaJavaScriptExtensions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TheEcmaScriptVersionToWhichTheCodeMustAdhere.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TheEcmaScriptVersionToWhichTheCodeMustAdhere.cs index f70d02c534d..df8fe53bafc 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TheEcmaScriptVersionToWhichTheCodeMustAdhere.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TheEcmaScriptVersionToWhichTheCodeMustAdhere.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public TheEcmaScriptVersionToWhichTheCodeMustAdhere Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TrailingcommaEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TrailingcommaEntity.cs index 7f67d4ff0e5..413de17fde9 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TrailingcommaEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.TrailingcommaEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public TrailingcommaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ValidthisEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ValidthisEntity.cs index 2309397a225..2645f925594 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ValidthisEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.ValidthisEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public ValidthisEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.VarstmtEntity.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.VarstmtEntity.cs index 63d8be0965d..84d9f73c05d 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.VarstmtEntity.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.VarstmtEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public VarstmtEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsAboutNonBreakingWhitespaceCharacters.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsAboutNonBreakingWhitespaceCharacters.cs index 428c437fa6f..5cec62fd7cb 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsAboutNonBreakingWhitespaceCharacters.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsAboutNonBreakingWhitespaceCharacters.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public WarnsAboutNonBreakingWhitespaceCharacters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsWhenYouDefineAndNeverUseYourVariables.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsWhenYouDefineAndNeverUseYourVariables.cs index c25d5b8a8da..141f1b1eb63 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsWhenYouDefineAndNeverUseYourVariables.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.WarnsWhenYouDefineAndNeverUseYourVariables.cs @@ -368,6 +368,12 @@ private void CheckValidInstance() public WarnsWhenYouDefineAndNeverUseYourVariables Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.cs index 8f7101af855..94854fe82a6 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JshintrcSchema.cs @@ -1806,6 +1806,12 @@ private void CheckValidInstance() public JshintrcSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonBoolean.cs index 9ac974e4c80..9f655385799 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonObject.cs index 30ef45c2b08..be4f739c9f0 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonString.cs index dac0fcca22a..47f7956e911 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/corvusjson-jsonschema.lock index d41d4018957..73bcc4ab116 100644 --- a/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.JshintrcBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:34.7442050\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:15.2682042\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonArray.cs index 943bfe11b1b..5e3c66d5ff7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonArray.cs @@ -34,11 +34,13 @@ namespace Corvus.KrakendBenchmark.Current; public readonly partial struct JsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public JsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonBoolean.cs index a8671700eda..0194489e812 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonBoolean.cs @@ -306,6 +306,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonInteger.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonInteger.cs index ea1bb974277..6fd9ebf9c49 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonInteger.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonInteger.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNull.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNull.cs index 4bcfcb69455..92efe5e246d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNull.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNull.cs @@ -256,6 +256,12 @@ private void CheckValidInstance() public JsonNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNumber.cs index dd107a8c5a0..184b5668a1c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonNumber.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonObject.cs index d33630ca3bd..e52c3eb8bc4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonObject.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonString.cs index 544e798f01f..2fb0dad59ea 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/JsonString.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.AutoAck.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.AutoAck.cs index 0b62649b79b..327a9780c0a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.AutoAck.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.AutoAck.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AutoAck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Delete.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Delete.cs index cfbf3dad2a6..eb87c8bd807 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Delete.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Delete.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Delete Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Durable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Durable.cs index b73d5364190..e739542dcf7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Durable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Durable.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Durable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Exclusive.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Exclusive.cs index d98771082f6..43bccee8bcc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Exclusive.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Exclusive.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Exclusive Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Mutable.cs index bd7891b8ff0..bf21b550114 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.Mutable.cs @@ -904,6 +904,61 @@ public bool RemovePrefetchSizeValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AutoAckValueUtf8, out IJsonDocument? _, out int _)) + { + SetAutoAckValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Amqp.AutoAck.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeleteValueUtf8, out IJsonDocument? _, out int _)) + { + SetDeleteValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Amqp.Delete.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DurableValueUtf8, out IJsonDocument? _, out int _)) + { + SetDurableValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Amqp.Durable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExclusiveValueUtf8, out IJsonDocument? _, out int _)) + { + SetExclusiveValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Amqp.Exclusive.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrefetchCountValueUtf8, out IJsonDocument? _, out int _)) + { + SetPrefetchCountValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Amqp.PrefetchCount.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrefetchSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetPrefetchSizeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Amqp.PrefetchSize.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchCount.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchCount.cs index 91174d5338b..6a2478652e7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchCount.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchCount.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public PrefetchCount Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchSize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchSize.cs index 0350b8e0498..5415ae8cb24 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchSize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.PrefetchSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public PrefetchSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.cs index 01a49d62c32..d5bbdad92ba 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Amqp.cs @@ -684,6 +684,12 @@ private void CheckValidInstance() public Amqp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Hash.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Hash.cs index 9dac497e4da..61bbb1c4214 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Hash.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Hash.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Hash Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Identifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Identifier.cs index 810c95ffccf..500f99a9778 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Identifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Identifier.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public Identifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.JsonStringArray.cs index c3125685e2d..9f2344dc790 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.JsonStringArray.cs @@ -35,11 +35,13 @@ public readonly partial struct KeysEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.Mutable.cs index 4447704fcbe..062d00bc9c0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.Mutable.cs @@ -347,6 +347,31 @@ public bool RemoveRoles() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.cs index 3117106e512..329030c848d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.KeysEntity.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public KeysEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.cs index e29d48bed68..5d9d435d3db 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.KeysEntityArray.cs @@ -31,11 +31,13 @@ public readonly partial struct ApiKeys public readonly partial struct KeysEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public KeysEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Mutable.cs index ea7fd6427ac..8ba3be40dd7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Mutable.cs @@ -610,6 +610,56 @@ public bool RemoveStrategyValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HashValueUtf8, out IJsonDocument? _, out int _)) + { + SetHashValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ApiKeys.Hash.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IdentifierValueUtf8, out IJsonDocument? _, out int _)) + { + SetIdentifierValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ApiKeys.Identifier.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropagateRoleUtf8, out IJsonDocument? _, out int _)) + { + SetPropagateRole(Corvus.KrakendBenchmark.Current.KrakendSchema.ApiKeys.PropagateRoleAsHeader.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SaltValueUtf8, out IJsonDocument? _, out int _)) + { + SetSaltValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ApiKeys.Salt.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StrategyValueUtf8, out IJsonDocument? _, out int _)) + { + SetStrategyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ApiKeys.Strategy.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.PropagateRoleAsHeader.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.PropagateRoleAsHeader.cs index 6b7b79678b2..2ed9a104025 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.PropagateRoleAsHeader.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.PropagateRoleAsHeader.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public PropagateRoleAsHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Salt.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Salt.cs index ca1fbaa9f7e..3c271f0a7c9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Salt.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Salt.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public Salt Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Strategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Strategy.cs index c83f38b1ed1..308e0791bc6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Strategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.Strategy.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Strategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.cs index 70f9c16fc08..7125f67e299 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ApiKeys.cs @@ -553,6 +553,12 @@ private void CheckValidInstance() public ApiKeys Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendArray.cs index 273fd868bbf..43d90b851df 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredBackendAndConsumerAndExtraConfigAndName public readonly partial struct BackendArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public BackendArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendEncoding.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendEncoding.cs index 4fd2f2f376a..7ee5b06fd62 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendEncoding.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendEncoding.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public BackendEncoding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.BackoffStrategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.BackoffStrategy.cs index 5f1af15e5e7..0ff877cf184 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.BackoffStrategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.BackoffStrategy.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public BackoffStrategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.MaxRetries.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.MaxRetries.cs index 419e874270e..099a0cd9999 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.MaxRetries.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.MaxRetries.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public MaxRetries Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.Mutable.cs index e22d499daf3..014da0f569d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.Mutable.cs @@ -384,6 +384,41 @@ public bool RemoveMaxRetriesValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackoffStrategyValueUtf8, out IJsonDocument? _, out int _)) + { + SetBackoffStrategyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.BackoffStrategy.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxRetriesValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxRetriesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.MaxRetries.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.cs index 690ed2a96c4..5a433952912 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.cs @@ -482,6 +482,12 @@ private void CheckValidInstance() public Connection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.MaxRate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.MaxRate.cs index 482bc6c792f..4ac24229d13 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.MaxRate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.MaxRate.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public MaxRate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Mutable.cs index 170edcb9eae..94e33a1b303 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Mutable.cs @@ -488,6 +488,41 @@ public bool RemoveWorkersValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxRateValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxRateValue(Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.MaxRate.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WorkersValueUtf8, out IJsonDocument? _, out int _)) + { + SetWorkersValue(Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Workers.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Workers.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Workers.cs index 6a66131408a..e4d1df2605f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Workers.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Workers.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public Workers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.cs index 303283f407a..7d1b942a821 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.cs @@ -457,6 +457,12 @@ private void CheckValidInstance() public Consumer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Mutable.cs index 6c7d3db17db..c6933f66de7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Mutable.cs @@ -679,6 +679,54 @@ public void SetName(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EncodingUtf8, out IJsonDocument? _, out int _)) + { + SetEncoding(Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.BackendEncoding.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConnectionValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Connection.Mutable __corvusConnectionValue)) + { + __corvusConnectionValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConsumerValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.Consumer.Mutable __corvusConsumerValue)) + { + __corvusConsumerValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtraConfigUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.Mutable __corvusExtraConfig)) + { + __corvusExtraConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.Mutable.cs index a5c94a79dcf..1f3668a9f2f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.Mutable.cs @@ -312,6 +312,37 @@ public void SetAsyncAmqp(in Corvus.KrakendBenchmark.Current.KrakendSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsyncAmqpUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Amqp.Mutable __corvusAsyncAmqp)) + { + __corvusAsyncAmqp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.cs index ce6a3f6b8fa..5a08fdfc741 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.RequiredAsyncAmqp.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public RequiredAsyncAmqp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.cs index 6fdb7975067..5e1d42c6107 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.RequiredBackendAndConsumerAndExtraConfigAndName.cs @@ -552,6 +552,12 @@ private void CheckValidInstance() public RequiredBackendAndConsumerAndExtraConfigAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.cs index 5453b872fe7..47bbbeb08cc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.AsyncAgent.cs @@ -469,6 +469,12 @@ private void CheckValidInstance() public AsyncAgent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowDataManipulation.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowDataManipulation.cs index 1e179a5e990..977363829aa 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowDataManipulation.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowDataManipulation.cs @@ -31,11 +31,13 @@ public readonly partial struct Backend public readonly partial struct AllowDataManipulation #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public AllowDataManipulation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowedQueArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowedQueArray.cs index b23afc46e7a..0fbec8d1d00 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowedQueArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.AllowedQueArray.cs @@ -39,11 +39,13 @@ public readonly partial struct Backend public readonly partial struct AllowedQueArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public AllowedQueArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.BackendEncoding.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.BackendEncoding.cs index 4593ea1cf34..311e6bfef43 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.BackendEncoding.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.BackendEncoding.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public BackendEncoding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DenyDataManipulation.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DenyDataManipulation.cs index c493048dc12..f22b3544f81 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DenyDataManipulation.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DenyDataManipulation.cs @@ -31,11 +31,13 @@ public readonly partial struct Backend public readonly partial struct DenyDataManipulation #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public DenyDataManipulation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DisableHostSanitize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DisableHostSanitize.cs index 851f898eb9f..a2708bd7e69 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DisableHostSanitize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.DisableHostSanitize.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DisableHostSanitize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.GroupDataManipulation.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.GroupDataManipulation.cs index a93942a548e..5e66c0c8e1f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.GroupDataManipulation.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.GroupDataManipulation.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public GroupDataManipulation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.IsACollectionArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.IsACollectionArray.cs index ede91a4fb5c..9d8f32b1208 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.IsACollectionArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.IsACollectionArray.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public IsACollectionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.JsonStringArray.cs index 4302a1c6d02..c3811654cac 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.JsonStringArray.cs @@ -39,11 +39,13 @@ public readonly partial struct Backend public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Method.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Method.cs index da8ab8cb170..5d980648ea1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Method.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Method.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Method Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Mutable.cs index 8b6cce542e2..1fc035de789 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.Mutable.cs @@ -1519,6 +1519,82 @@ public void SetUrlPattern(scoped in Corvus.KrakendBenchmark.Current.JsonString.S _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableHostSanitizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableHostSanitizeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.DisableHostSanitize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EncodingUtf8, out IJsonDocument? _, out int _)) + { + SetEncoding(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.BackendEncoding.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GroupUtf8, out IJsonDocument? _, out int _)) + { + SetGroup(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.GroupDataManipulation.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputHeadersUtf8, out IJsonDocument? _, out int _)) + { + SetInputHeaders(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputQueryStringsUtf8, out IJsonDocument? _, out int _)) + { + SetInputQueryStrings(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.AllowedQueArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsCollectionUtf8, out IJsonDocument? _, out int _)) + { + SetIsCollection(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.IsACollectionArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MethodValueUtf8, out IJsonDocument? _, out int _)) + { + SetMethodValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.Method.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SdUtf8, out IJsonDocument? _, out int _)) + { + SetSd(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.ServiceDiscovery.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SdSchemeUtf8, out IJsonDocument? _, out int _)) + { + SetSdScheme(Corvus.KrakendBenchmark.Current.KrakendSchema.Backend.ServiceDiscoveryScheme.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtraConfigUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BackendExtraConfig.Mutable __corvusExtraConfig)) + { + __corvusExtraConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscovery.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscovery.cs index 0c9ded2a01f..77aec33be1c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscovery.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscovery.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ServiceDiscovery Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscoveryScheme.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscoveryScheme.cs index 01a11bdb196..eb69b5a3246 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscoveryScheme.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.ServiceDiscoveryScheme.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public ServiceDiscoveryScheme Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.cs index dde6d13c246..eadca110955 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Backend.cs @@ -791,6 +791,12 @@ private void CheckValidInstance() public Backend Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.Mutable.cs index cf4dc5ece4c..788f60edd78 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.Mutable.cs @@ -390,6 +390,31 @@ public bool RemoveReturnErrorDetails() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.Mutable.cs index f4fb3017841..1af88f3fbf1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.Mutable.cs @@ -302,6 +302,31 @@ public void SetReturnErrorCode(in Corvus.Text.Json.JsonElement.Source< _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.cs index ef7c4ab0c31..7f487ae8a80 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorCode.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredReturnErrorCode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.Mutable.cs index cd263f71009..01076caf6c6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.Mutable.cs @@ -302,6 +302,31 @@ public void SetReturnErrorDetails(in Corvus.Text.Json.JsonElement.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.cs index 83d90120698..03488bd7b9e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.RequiredReturnErrorDetails.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredReturnErrorDetails Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.cs index a1096b8adf9..56f49bc3716 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Backend1httpEntity.cs @@ -445,6 +445,12 @@ private void CheckValidInstance() public Backend1httpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.Mutable.cs index 07712330d2e..da71153f623 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.Mutable.cs @@ -239,6 +239,31 @@ public bool RemoveShared() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.cs index 8e180386b1f..650ca745b76 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.BackendCache.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public BackendCache Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Mutable.cs index c61abd7e416..6d4157bf0f5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.Mutable.cs @@ -3288,6 +3288,205 @@ public bool RemoveWorkflowValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthClientCredentialsUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ClientCredentials.Mutable __corvusAuthClientCredentials)) + { + __corvusAuthClientCredentials.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthGcpUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Gcp.Mutable __corvusAuthGcp)) + { + __corvusAuthGcp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthNtlmUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Ntlm.Mutable __corvusAuthNtlm)) + { + __corvusAuthNtlm.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendAmqpConsumerUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.Mutable __corvusBackendAmqpConsumer)) + { + __corvusBackendAmqpConsumer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendAmqpProducerUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.Mutable __corvusBackendAmqpProducer)) + { + __corvusBackendAmqpProducer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendGraphqlUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Graphql.Mutable __corvusBackendGraphql)) + { + __corvusBackendGraphql.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendGrpcUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.Mutable __corvusBackendGrpc)) + { + __corvusBackendGrpc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendHttpUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BackendExtraConfig.Backend1httpEntity.Mutable __corvusBackendHttp)) + { + __corvusBackendHttp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendHttpClientUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.HttpClient.Mutable __corvusBackendHttpClient)) + { + __corvusBackendHttpClient.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendLambdaUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Lambda.Mutable __corvusBackendLambda)) + { + __corvusBackendLambda.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendPubsubPublisherUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Publisher.Mutable __corvusBackendPubsubPublisher)) + { + __corvusBackendPubsubPublisher.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendPubsubSubscriberUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Subscriber.Mutable __corvusBackendPubsubSubscriber)) + { + __corvusBackendPubsubSubscriber.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendSoapUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Soap.Mutable __corvusBackendSoap)) + { + __corvusBackendSoap.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendStaticFilesystemUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.StaticFilesystem.Mutable __corvusBackendStaticFilesystem)) + { + __corvusBackendStaticFilesystem.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierBodyGeneratorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.Mutable __corvusModifierBodyGenerator)) + { + __corvusModifierBodyGenerator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierJmespathUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Jmespath.Mutable __corvusModifierJmespath)) + { + __corvusModifierJmespath.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierLuaBackendUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.Mutable __corvusModifierLuaBackend)) + { + __corvusModifierLuaBackend.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierMartianUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifierMartian)) + { + __corvusModifierMartian.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierRequestBodyGeneratorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.Mutable __corvusModifierRequestBodyGenerator)) + { + __corvusModifierRequestBodyGenerator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierResponseBodyGeneratorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.Mutable __corvusModifierResponseBodyGenerator)) + { + __corvusModifierResponseBodyGenerator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginHttpClientValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.PluginHttpClient.Mutable __corvusPluginHttpClientValue)) + { + __corvusPluginHttpClientValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginReqRespModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ReqRespModifier.Mutable __corvusPluginReqRespModifier)) + { + __corvusPluginReqRespModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProxyValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Proxy.Mutable __corvusProxyValue)) + { + __corvusProxyValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QosCircuitBreakerUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.CircuitBreaker.Mutable __corvusQosCircuitBreaker)) + { + __corvusQosCircuitBreaker.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QosHttpCacheUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BackendExtraConfig.BackendCache.Mutable __corvusQosHttpCache)) + { + __corvusQosHttpCache.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QosRatelimitProxyUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.RatelimitProxy.Mutable __corvusQosRatelimitProxy)) + { + __corvusQosRatelimitProxy.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityPoliciesUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.Mutable __corvusSecurityPolicies)) + { + __corvusSecurityPolicies.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryOpentelemetryUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.Mutable __corvusTelemetryOpentelemetry)) + { + __corvusTelemetryOpentelemetry.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WorkflowValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Workflow.Mutable __corvusWorkflowValue)) + { + __corvusWorkflowValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.cs index 80a5d6fb868..fd76a2b9209 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BackendExtraConfig.cs @@ -1083,6 +1083,12 @@ private void CheckValidInstance() public BackendExtraConfig Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.Entity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.Entity.cs index db0868c4d62..9276a50f32d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.Entity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.Entity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.cs index 2272d38c13e..72183dede3a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.AdditionalUsers.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public AdditionalUsers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.Mutable.cs index b1d8ce4ac3f..84352d7eba9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.Mutable.cs @@ -343,6 +343,31 @@ public bool RemoveUsers() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.cs index 85aa410737c..a909b0c1313 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Basic.cs @@ -450,6 +450,12 @@ private void CheckValidInstance() public Basic Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.ContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.ContentType.cs index 315ea05bd6b..7c9fb48c7ff 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.ContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.ContentType.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public ContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.EnableDebug.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.EnableDebug.cs index e46c0670912..83bdb06b927 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.EnableDebug.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.EnableDebug.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EnableDebug Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.Mutable.cs index 960f78e8ec7..47ef2c275a8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.Mutable.cs @@ -552,6 +552,41 @@ public bool RemoveTemplate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentTypeValueUtf8, out IJsonDocument? _, out int _)) + { + SetContentTypeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.ContentType.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.EnableDebug.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.Mutable.cs index 3aa840d49e7..d81d0b1b933 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.Mutable.cs @@ -300,6 +300,31 @@ public void SetPath(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.cs index 342f7df0d95..1686def70ae 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredPath.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.Mutable.cs index a696d3e5ea3..011f3692944 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.Mutable.cs @@ -300,6 +300,31 @@ public void SetTemplate(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.cs index 58a1fe1b1bc..7377a57e049 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.RequiredTemplate.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.cs index 76768622673..3d5afb63d48 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BodyGenerator.cs @@ -623,6 +623,12 @@ private void CheckValidInstance() public BodyGenerator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Allow.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Allow.cs index 2c79ca2429b..101e9ad6dc0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Allow.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Allow.cs @@ -49,11 +49,13 @@ public readonly partial struct BotDetector public readonly partial struct Allow #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -99,6 +101,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -312,6 +329,12 @@ private void CheckValidInstance() public Allow Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.BotPatterns.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.BotPatterns.cs index fc809f94820..4f0ad3b7875 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.BotPatterns.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.BotPatterns.cs @@ -49,11 +49,13 @@ public readonly partial struct BotDetector public readonly partial struct BotPatterns #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -99,6 +101,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -312,6 +329,12 @@ private void CheckValidInstance() public BotPatterns Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Deny.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Deny.cs index 152e33278d8..a2819c5273d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Deny.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Deny.cs @@ -44,11 +44,13 @@ public readonly partial struct BotDetector public readonly partial struct Deny #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public Deny Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.EmptyUserAgentIsABot.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.EmptyUserAgentIsABot.cs index 1fd9beb8e5d..f956af75f58 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.EmptyUserAgentIsABot.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.EmptyUserAgentIsABot.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EmptyUserAgentIsABot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Mutable.cs index 074d97f6ac5..04be0dc933e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.Mutable.cs @@ -625,6 +625,51 @@ public bool RemovePatterns() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowValue(Corvus.KrakendBenchmark.Current.KrakendSchema.BotDetector.Allow.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DenyValueUtf8, out IJsonDocument? _, out int _)) + { + SetDenyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.BotDetector.Deny.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EmptyUserAgentIsBotUtf8, out IJsonDocument? _, out int _)) + { + SetEmptyUserAgentIsBot(Corvus.KrakendBenchmark.Current.KrakendSchema.BotDetector.EmptyUserAgentIsABot.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PatternsUtf8, out IJsonDocument? _, out int _)) + { + SetPatterns(Corvus.KrakendBenchmark.Current.KrakendSchema.BotDetector.BotPatterns.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.cs index 065a087be55..c6369bed5e6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.BotDetector.cs @@ -525,6 +525,12 @@ private void CheckValidInstance() public BotDetector Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.Mutable.cs index 0c11b3f8188..ca9e1e66e4b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.Mutable.cs @@ -228,6 +228,31 @@ public void SetCheckExpr(scoped in Corvus.KrakendBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.cs index 55f8eb0c00e..5d7efc6a97e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.ObjectInArray.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public ObjectInArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.cs index f8e6b1edd09..f7dd1229d91 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cel.cs @@ -29,11 +29,13 @@ public readonly partial struct KrakendSchema public readonly partial struct Cel #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public Cel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.LogStatusChange.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.LogStatusChange.cs index 44f88f829c0..68df4ce6ee6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.LogStatusChange.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.LogStatusChange.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public LogStatusChange Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.Mutable.cs index 5439843a588..36a5d78f86b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.Mutable.cs @@ -484,6 +484,36 @@ public void SetTimeout(scoped in Corvus.KrakendBenchmark.Current.JsonInteger.Sou _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LogStatusChangeValueUtf8, out IJsonDocument? _, out int _)) + { + SetLogStatusChangeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.CircuitBreaker.LogStatusChange.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.cs index fa2fb4f0c1d..a4bf819bfbb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.CircuitBreaker.cs @@ -534,6 +534,12 @@ private void CheckValidInstance() public CircuitBreaker Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.Mutable.cs index b27e85c6840..912c925b23a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.Mutable.cs @@ -520,6 +520,31 @@ public void SetTokenUrl(scoped in Corvus.KrakendBenchmark.Current.JsonString.Sou _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.cs index 7eb94298dfc..fdcba12d3fd 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientCredentials.cs @@ -534,6 +534,12 @@ private void CheckValidInstance() public ClientCredentials Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.AllowInsecureConnections.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.AllowInsecureConnections.cs index ffcb616aaf4..c7e09a4b238 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.AllowInsecureConnections.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.AllowInsecureConnections.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AllowInsecureConnections Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CaCertificates.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CaCertificates.cs index 72fc3d17933..940db718998 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CaCertificates.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CaCertificates.cs @@ -39,11 +39,13 @@ public readonly partial struct ClientTls public readonly partial struct CaCertificates #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public CaCertificates Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CipherSuites.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CipherSuites.cs index c9bb5502ce0..c69b608305c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CipherSuites.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CipherSuites.cs @@ -39,11 +39,13 @@ public readonly partial struct ClientTls public readonly partial struct CipherSuites #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public CipherSuites Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs index 71c4c2d68a5..865b86fa4d7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public CurvePreferencesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.cs index 1c243199eda..d0ec32579eb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.CurvePreferencesEntityArray.cs @@ -39,11 +39,13 @@ public readonly partial struct ClientTls public readonly partial struct CurvePreferencesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -122,6 +124,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -335,6 +352,12 @@ private void CheckValidInstance() public CurvePreferencesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.DisableSystemSCa.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.DisableSystemSCa.cs index af670e7fb9c..9110cbbe779 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.DisableSystemSCa.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.DisableSystemSCa.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableSystemSCa Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MaximumTlsVersion.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MaximumTlsVersion.cs index ed1eaca6a83..618b268b256 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MaximumTlsVersion.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MaximumTlsVersion.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public MaximumTlsVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MinimumTlsVersion.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MinimumTlsVersion.cs index 953ecad2310..33cba38028c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MinimumTlsVersion.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.MinimumTlsVersion.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public MinimumTlsVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.Mutable.cs index c03d45eb02c..be1ebc546f4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.Mutable.cs @@ -868,6 +868,66 @@ public bool RemoveMinVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowInsecureConnectionsValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowInsecureConnectionsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.AllowInsecureConnections.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CaCertsUtf8, out IJsonDocument? _, out int _)) + { + SetCaCerts(Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.CaCertificates.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CipherSuitesValueUtf8, out IJsonDocument? _, out int _)) + { + SetCipherSuitesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.CipherSuites.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CurvePreferencesUtf8, out IJsonDocument? _, out int _)) + { + SetCurvePreferences(Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.CurvePreferencesEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableSystemCaPoolUtf8, out IJsonDocument? _, out int _)) + { + SetDisableSystemCaPool(Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.DisableSystemSCa.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxVersionUtf8, out IJsonDocument? _, out int _)) + { + SetMaxVersion(Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.MaximumTlsVersion.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinVersionUtf8, out IJsonDocument? _, out int _)) + { + SetMinVersion(Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.MinimumTlsVersion.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.Mutable.cs index fae22ebfee5..c45c39e45a7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.Mutable.cs @@ -283,6 +283,31 @@ public void SetPrivateKey(scoped in Corvus.KrakendBenchmark.Current.JsonString.S _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.cs index 0e7bb38ae3a..903e50170a5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.RequiredCertificateAndPrivateKey.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public RequiredCertificateAndPrivateKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.cs index b11e8386c9a..f77f26280a9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.RequiredCertificateAndPrivateKeyArray.cs @@ -31,11 +31,13 @@ public readonly partial struct ClientTls public readonly partial struct RequiredCertificateAndPrivateKeyArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public RequiredCertificateAndPrivateKeyArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.cs index 4d16a42193e..f92103b3c0b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ClientTls.cs @@ -597,6 +597,12 @@ private void CheckValidInstance() public ClientTls Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.AutoAck.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.AutoAck.cs index 2c4cbef4dbb..7555b84ad8b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.AutoAck.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.AutoAck.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AutoAck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.BackoffStrategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.BackoffStrategy.cs index df9b7eac65c..e6f52e92e9e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.BackoffStrategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.BackoffStrategy.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public BackoffStrategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Delete.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Delete.cs index ee8949ff2b4..269a5622e27 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Delete.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Delete.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Delete Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Durable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Durable.cs index 2f94757596b..909715cd5f4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Durable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Durable.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Durable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Exclusive.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Exclusive.cs index e2194dc967e..a23f6198253 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Exclusive.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Exclusive.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Exclusive Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.MaxRetries.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.MaxRetries.cs index 58b573f7e0a..f38febc6be9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.MaxRetries.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.MaxRetries.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaxRetries Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Mutable.cs index 45450057150..ffbf474b2d5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.Mutable.cs @@ -1008,6 +1008,66 @@ public void SetRoutingKey(in Corvus.KrakendBenchmark.Current.JsonArray _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AutoAckValueUtf8, out IJsonDocument? _, out int _)) + { + SetAutoAckValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.AutoAck.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackoffStrategyValueUtf8, out IJsonDocument? _, out int _)) + { + SetBackoffStrategyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.BackoffStrategy.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeleteValueUtf8, out IJsonDocument? _, out int _)) + { + SetDeleteValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.Delete.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DurableValueUtf8, out IJsonDocument? _, out int _)) + { + SetDurableValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.Durable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExclusiveValueUtf8, out IJsonDocument? _, out int _)) + { + SetExclusiveValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.Exclusive.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxRetriesValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxRetriesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.MaxRetries.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrefetchCountValueUtf8, out IJsonDocument? _, out int _)) + { + SetPrefetchCountValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Consumer.PrefetchCount.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.PrefetchCount.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.PrefetchCount.cs index cc7c5a14d6f..0d8570b4c6e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.PrefetchCount.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.PrefetchCount.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public PrefetchCount Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.cs index bd72ee8ee39..91a81065e50 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Consumer.cs @@ -709,6 +709,12 @@ private void CheckValidInstance() public Consumer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.IsARegexp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.IsARegexp.cs index 3e70fdc5221..93e5c0fb738 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.IsARegexp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.IsARegexp.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public IsARegexp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.Mutable.cs index 2630c78cee8..928bea5acf5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.Mutable.cs @@ -357,6 +357,36 @@ public void SetReplace(scoped in Corvus.KrakendBenchmark.Current.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RegexpUtf8, out IJsonDocument? _, out int _)) + { + SetRegexp(Corvus.KrakendBenchmark.Current.KrakendSchema.ContentReplacer.RequiredFindAndReplace.IsARegexp.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.cs index fe382754ee1..56408294310 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.RequiredFindAndReplace.cs @@ -475,6 +475,12 @@ private void CheckValidInstance() public RequiredFindAndReplace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.cs index 49928d93a76..5fbc1bb4ca2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ContentReplacer.cs @@ -347,6 +347,12 @@ private void CheckValidInstance() public ContentReplacer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowCredentials.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowCredentials.cs index 79554005002..c38dc05fd50 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowCredentials.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowCredentials.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AllowCredentials Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.AllowMethodsEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.AllowMethodsEntity.cs index 9274d7a3575..4d45966031b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.AllowMethodsEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.AllowMethodsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AllowMethodsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.cs index cef422d7500..962286c4d77 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowMethodsEntityArray.cs @@ -39,11 +39,13 @@ public readonly partial struct Cors public readonly partial struct AllowMethodsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public AllowMethodsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowPrivateNetwork.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowPrivateNetwork.cs index 0d1740fa5e5..ae81336df2d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowPrivateNetwork.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowPrivateNetwork.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AllowPrivateNetwork Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedHeaders.cs index 1920bb4c2f7..ee98e2008aa 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedHeaders.cs @@ -39,11 +39,13 @@ public readonly partial struct Cors public readonly partial struct AllowedHeaders #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public AllowedHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedOrigins.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedOrigins.cs index 02c20cc94f4..2a8ecea6fe0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedOrigins.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.AllowedOrigins.cs @@ -39,11 +39,13 @@ public readonly partial struct Cors public readonly partial struct AllowedOrigins #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public AllowedOrigins Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.DevelopmentFlag.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.DevelopmentFlag.cs index 625b8e8e382..be8767e681d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.DevelopmentFlag.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.DevelopmentFlag.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DevelopmentFlag Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.ExposeHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.ExposeHeaders.cs index 88c675a4993..8c4f5b08224 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.ExposeHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.ExposeHeaders.cs @@ -39,11 +39,13 @@ public readonly partial struct Cors public readonly partial struct ExposeHeaders #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public ExposeHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.Mutable.cs index fc561a02cb8..399c18a1183 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.Mutable.cs @@ -1014,6 +1014,76 @@ public bool RemoveOptionsSuccessStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowCredentialsValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowCredentialsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.AllowCredentials.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowHeadersUtf8, out IJsonDocument? _, out int _)) + { + SetAllowHeaders(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.AllowedHeaders.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowMethodsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowMethods(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.AllowMethodsEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowOriginsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowOrigins(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.AllowedOrigins.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowPrivateNetworkValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowPrivateNetworkValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.AllowPrivateNetwork.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.DevelopmentFlag.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExposeHeadersValueUtf8, out IJsonDocument? _, out int _)) + { + SetExposeHeadersValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.ExposeHeaders.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionsPassthroughValueUtf8, out IJsonDocument? _, out int _)) + { + SetOptionsPassthroughValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.OptionsPassthrough.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionsSuccessStatusUtf8, out IJsonDocument? _, out int _)) + { + SetOptionsSuccessStatus(Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.SuccessStatusCodes.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.OptionsPassthrough.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.OptionsPassthrough.cs index 3b7c3f13adb..b666b2a20eb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.OptionsPassthrough.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.OptionsPassthrough.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public OptionsPassthrough Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.SuccessStatusCodes.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.SuccessStatusCodes.cs index ea212fed891..41125ead4c4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.SuccessStatusCodes.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.SuccessStatusCodes.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public SuccessStatusCodes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.cs index 041fd6cb648..e7dc9c771bf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Cors.cs @@ -653,6 +653,12 @@ private void CheckValidInstance() public Cors Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DebugEndpoint.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DebugEndpoint.cs index 16962d11658..7307f03811f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DebugEndpoint.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DebugEndpoint.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public DebugEndpoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableCompression.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableCompression.cs index a85321dc2ae..4444abaaff1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableCompression.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableCompression.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DisableCompression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableKeepAlives.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableKeepAlives.cs index c7bf587f51f..eb6331158ea 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableKeepAlives.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableKeepAlives.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DisableKeepAlives Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableResTfulUrLs.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableResTfulUrLs.cs index f7ffa7fdb5c..ddf9a8fc502 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableResTfulUrLs.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.DisableResTfulUrLs.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public DisableResTfulUrLs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Duration.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Duration.cs index ce11fa00476..320f7efa139 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Duration.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Duration.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public Duration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EchoEndpoint.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EchoEndpoint.cs index 8dcb7efe30a..0e149553541 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EchoEndpoint.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EchoEndpoint.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public EchoEndpoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EnableH2c.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EnableH2c.cs index c0b5407f779..56422bf034c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EnableH2c.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EnableH2c.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public EnableH2c Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.AllowedQueArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.AllowedQueArray.cs index 217c31422ba..7adb0713abe 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.AllowedQueArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.AllowedQueArray.cs @@ -45,11 +45,13 @@ public readonly partial struct Endpoint public readonly partial struct AllowedQueArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -100,6 +102,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -313,6 +330,12 @@ private void CheckValidInstance() public AllowedQueArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.BackendArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.BackendArray.cs index b7e4c6d0b13..fb469f2d99e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.BackendArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.BackendArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Endpoint public readonly partial struct BackendArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public BackendArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.ConcurrentCalls.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.ConcurrentCalls.cs index f438c7f03cf..a263e366a1d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.ConcurrentCalls.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.ConcurrentCalls.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ConcurrentCalls Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.EndpointEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.EndpointEntity.cs index d01f02f9745..33085e1b20f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.EndpointEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.EndpointEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public EndpointEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.JsonStringArray.cs index a28909ff6e2..3e93f1c0036 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.JsonStringArray.cs @@ -42,11 +42,13 @@ public readonly partial struct Endpoint public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -97,6 +99,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -310,6 +327,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Method.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Method.cs index 56889b13722..45db4c5999f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Method.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Method.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Method Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Mutable.cs index f701730ceb5..9fd55364a71 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.Mutable.cs @@ -997,6 +997,62 @@ public bool RemoveTimeout() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConcurrentCallsValueUtf8, out IJsonDocument? _, out int _)) + { + SetConcurrentCallsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Endpoint.ConcurrentCalls.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputHeadersUtf8, out IJsonDocument? _, out int _)) + { + SetInputHeaders(Corvus.KrakendBenchmark.Current.KrakendSchema.Endpoint.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputQueryStringsUtf8, out IJsonDocument? _, out int _)) + { + SetInputQueryStrings(Corvus.KrakendBenchmark.Current.KrakendSchema.Endpoint.AllowedQueArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MethodValueUtf8, out IJsonDocument? _, out int _)) + { + SetMethodValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Endpoint.Method.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputEncodingValueUtf8, out IJsonDocument? _, out int _)) + { + SetOutputEncodingValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Endpoint.OutputEncoding.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtraConfigUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.EndpointExtraConfig.Mutable __corvusExtraConfig)) + { + __corvusExtraConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.OutputEncoding.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.OutputEncoding.cs index 3886361af18..329b18eab64 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.OutputEncoding.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.OutputEncoding.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public OutputEncoding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.cs index 1358782456b..a39d7d8cd27 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Endpoint.cs @@ -666,6 +666,12 @@ private void CheckValidInstance() public Endpoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointArray.cs index b441e301bff..a88e07c6ed7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointArray.cs @@ -29,11 +29,13 @@ public readonly partial struct KrakendSchema public readonly partial struct EndpointArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public EndpointArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.JsonStringArray.cs index f27302c92f1..7d3fa7a9903 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.JsonStringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct ApiKeyValidation public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Mutable.cs index 4ef7e7d486a..3182940885d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Mutable.cs @@ -472,6 +472,31 @@ public bool RemoveStrategyValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Strategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Strategy.cs index d244843a7fe..60067453d1f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Strategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Strategy.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public Strategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.cs index cc3ba1d9433..0bf45a1545a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.ApiKeyValidation.cs @@ -505,6 +505,12 @@ private void CheckValidInstance() public ApiKeyValidation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Mutable.cs index 27e5a031c7b..b589a6cb536 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Mutable.cs @@ -2462,6 +2462,151 @@ public bool RemoveWebsocketValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthApiKeysUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.EndpointExtraConfig.ApiKeyValidation.Mutable __corvusAuthApiKeys)) + { + __corvusAuthApiKeys.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthBasicUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Basic.Mutable __corvusAuthBasic)) + { + __corvusAuthBasic.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthSignerUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Signer.Mutable __corvusAuthSigner)) + { + __corvusAuthSigner.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthValidatorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.Mutable __corvusAuthValidator)) + { + __corvusAuthValidator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentationOpenapiUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Openapi.Mutable __corvusDocumentationOpenapi)) + { + __corvusDocumentationOpenapi.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierJmespathUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Jmespath.Mutable __corvusModifierJmespath)) + { + __corvusModifierJmespath.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierLuaEndpointUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.Mutable __corvusModifierLuaEndpoint)) + { + __corvusModifierLuaEndpoint.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierLuaProxyUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.Mutable __corvusModifierLuaProxy)) + { + __corvusModifierLuaProxy.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierRequestBodyGeneratorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.Mutable __corvusModifierRequestBodyGenerator)) + { + __corvusModifierRequestBodyGenerator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierResponseBodyGeneratorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.Mutable __corvusModifierResponseBodyGenerator)) + { + __corvusModifierResponseBodyGenerator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginReqRespModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ReqRespModifier.Mutable __corvusPluginReqRespModifier)) + { + __corvusPluginReqRespModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProxyValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.EndpointExtraConfig.Proxy.Mutable __corvusProxyValue)) + { + __corvusProxyValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QosRatelimitRouterUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Router.Mutable __corvusQosRatelimitRouter)) + { + __corvusQosRatelimitRouter.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QosRatelimitTieredUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Tiered.Mutable __corvusQosRatelimitTiered)) + { + __corvusQosRatelimitTiered.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityBotDetectorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BotDetector.Mutable __corvusSecurityBotDetector)) + { + __corvusSecurityBotDetector.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityCorsUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Cors.Mutable __corvusSecurityCors)) + { + __corvusSecurityCors.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityHttpUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Http.Mutable __corvusSecurityHttp)) + { + __corvusSecurityHttp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityPoliciesUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.Mutable __corvusSecurityPolicies)) + { + __corvusSecurityPolicies.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryOpentelemetryUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryEndpoint.Mutable __corvusTelemetryOpentelemetry)) + { + __corvusTelemetryOpentelemetry.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WebsocketValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.Mutable __corvusWebsocketValue)) + { + __corvusWebsocketValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.Mutable.cs index fa554bc8730..9bdcb41809c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.Mutable.cs @@ -524,6 +524,42 @@ public bool RemoveStatic() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SequentialUtf8, out IJsonDocument? _, out int _)) + { + SetSequential(Corvus.KrakendBenchmark.Current.KrakendSchema.EndpointExtraConfig.Proxy.SequentialProxy.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StaticUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Mutable __corvusStatic)) + { + __corvusStatic.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.SequentialProxy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.SequentialProxy.cs index c0eee5afc15..f1a4e3f0202 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.SequentialProxy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.SequentialProxy.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public SequentialProxy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Mutable.cs index 9fe317a4541..0cb306dd9d8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Mutable.cs @@ -323,6 +323,31 @@ public void SetStrategyValue(scoped in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Strategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Strategy.cs index d4d75d34cb0..494074c07ae 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Strategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.Strategy.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public Strategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.cs index 8066c92d114..5aca5512e56 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.StaticResponse.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public StaticResponse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.cs index 940b2d06337..b2a3f71b23f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.Proxy.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public Proxy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.cs index 0882952bc3e..81fa101a778 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.EndpointExtraConfig.cs @@ -905,6 +905,12 @@ private void CheckValidInstance() public EndpointExtraConfig Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Mutable.cs index 0a92cbe45b1..1d04384810d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Mutable.cs @@ -321,6 +321,31 @@ public void SetTypeValue(scoped in Corvus.KrakendBenchmark.Current.KrakendSchema _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Type.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Type.cs index a7c4f766e12..2cde4555891 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Type.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.Type.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public Type Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.cs index 30488fcdb82..61c6b1a16b5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.FlatmapOperation.cs @@ -450,6 +450,12 @@ private void CheckValidInstance() public FlatmapOperation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.cs index 2346f679870..46fe30c8176 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Flatmap.cs @@ -29,11 +29,13 @@ public readonly partial struct KrakendSchema public readonly partial struct Flatmap #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public Flatmap Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.Mutable.cs index 9595a4b05b8..4a05e8ea967 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.Mutable.cs @@ -573,6 +573,31 @@ public bool RemoveCustomClaims() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.Mutable.cs index ddd9b95c4db..7249d70b35d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.Mutable.cs @@ -300,6 +300,31 @@ public void SetAudience(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.cs index ffe3feecba5..0bf62a6fd18 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudience.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredAudience Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.Mutable.cs index 189a5269d20..5f215e89ecd 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.Mutable.cs @@ -386,6 +386,31 @@ public void SetCredentialsFile(in Corvus.Text.Json.JsonElement.Source< _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.cs index b17dd540347..8f59cad5323 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsFile.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredAudienceAndCredentialsFile Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.Mutable.cs index ea2d26cc1d0..54df03c444d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.Mutable.cs @@ -386,6 +386,31 @@ public void SetCredentialsJson(in Corvus.Text.Json.JsonElement.Source< _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.cs index ca38387d84d..4fce3856c9c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.RequiredAudienceAndCredentialsJson.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredAudienceAndCredentialsJson Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.cs index 7bcaf14fafe..24e92c25411 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gcp.cs @@ -581,6 +581,12 @@ private void CheckValidInstance() public Gcp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.Mutable.cs index 28944475e81..bf4e370443f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.Mutable.cs @@ -285,6 +285,31 @@ public void SetEnableTcp(scoped in Corvus.KrakendBenchmark.Current.JsonBoolean.S _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.cs index d5df4968296..786e1682e1e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Gelf.cs @@ -456,6 +456,12 @@ private void CheckValidInstance() public Gelf Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.Mutable.cs index 04c1ff21676..7a36f763dde 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.Mutable.cs @@ -226,6 +226,31 @@ public void SetCitydbPath(scoped in Corvus.KrakendBenchmark.Current.JsonString.S _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.cs index b661a45bdd8..6c3cfc64a83 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Geoip.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public Geoip Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.Mutable.cs index 3f84de4b266..f422b22b77e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.Mutable.cs @@ -589,6 +589,31 @@ public bool RemoveVariables() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.QueryType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.QueryType.cs index 4b244521e63..e57c9c7201c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.QueryType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.QueryType.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public QueryType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.Mutable.cs index c7ecf8b66a3..8eb9eda0958 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.Mutable.cs @@ -386,6 +386,31 @@ public void SetType(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.cs index 0fe5408fb37..8586d51e6a0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryAndType.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredQueryAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.Mutable.cs index a1eea4b5702..5ae70025fa7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.Mutable.cs @@ -386,6 +386,31 @@ public void SetType(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.cs index d8ff930aa0e..8203d11e949 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.RequiredQueryPathAndType.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredQueryPathAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.cs index aadbad8e9bb..92ee734cdb7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Graphql.cs @@ -576,6 +576,12 @@ private void CheckValidInstance() public Graphql Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.DisableQueryParameters.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.DisableQueryParameters.cs index fea15d808a3..8849c78a462 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.DisableQueryParameters.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.DisableQueryParameters.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableQueryParameters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfHeaders.cs index 6278d48e5fe..fcea4acc872 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfHeaders.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public MappingOfHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfParameters.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfParameters.cs index 1a22853a2fb..0866ed036b0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfParameters.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.MappingOfParameters.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public MappingOfParameters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.Mutable.cs index 428fb826953..d7f857031f1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.Mutable.cs @@ -1121,6 +1121,77 @@ public bool RemoveUseRequestBody() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableQueryParamsUtf8, out IJsonDocument? _, out int _)) + { + SetDisableQueryParams(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.DisableQueryParameters.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputDurationAsStringUtf8, out IJsonDocument? _, out int _)) + { + SetOutputDurationAsString(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.OutputDurationTypesAsString.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputEnumAsStringUtf8, out IJsonDocument? _, out int _)) + { + SetOutputEnumAsString(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.OutputEnumTypesAsString.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputRemoveUnsetValuesUtf8, out IJsonDocument? _, out int _)) + { + SetOutputRemoveUnsetValues(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.OutputRemovesUnsetValues.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputTimestampAsStringUtf8, out IJsonDocument? _, out int _)) + { + SetOutputTimestampAsString(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.OutputTimestampsTypesAsString.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequestNamingConventionValueUtf8, out IJsonDocument? _, out int _)) + { + SetRequestNamingConventionValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.RequestNamingConvention.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResponseNamingConventionValueUtf8, out IJsonDocument? _, out int _)) + { + SetResponseNamingConventionValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.ResponseNamingConvention.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseRequestBodyUtf8, out IJsonDocument? _, out int _)) + { + SetUseRequestBody(Corvus.KrakendBenchmark.Current.KrakendSchema.Grpc.UseBody.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ClientTlsValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.Mutable __corvusClientTlsValue)) + { + __corvusClientTlsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputDurationTypesAsString.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputDurationTypesAsString.cs index df1c5899d3d..91020697ef1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputDurationTypesAsString.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputDurationTypesAsString.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public OutputDurationTypesAsString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputEnumTypesAsString.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputEnumTypesAsString.cs index 3ce5d639761..e6311ab4745 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputEnumTypesAsString.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputEnumTypesAsString.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public OutputEnumTypesAsString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputRemovesUnsetValues.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputRemovesUnsetValues.cs index cc4092e297e..78c26285932 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputRemovesUnsetValues.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputRemovesUnsetValues.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public OutputRemovesUnsetValues Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputTimestampsTypesAsString.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputTimestampsTypesAsString.cs index a2b33f70a9a..4f19e63bba2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputTimestampsTypesAsString.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.OutputTimestampsTypesAsString.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public OutputTimestampsTypesAsString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.RequestNamingConvention.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.RequestNamingConvention.cs index bfac1197a3b..b9a53be1b4a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.RequestNamingConvention.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.RequestNamingConvention.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public RequestNamingConvention Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.ResponseNamingConvention.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.ResponseNamingConvention.cs index 9b34b730f77..46ea8dcec0b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.ResponseNamingConvention.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.ResponseNamingConvention.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ResponseNamingConvention Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.UseBody.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.UseBody.cs index 091a7b4a464..cd2ee5d2caf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.UseBody.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.UseBody.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public UseBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.cs index 5fbdb23cb50..f260056b277 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Grpc.cs @@ -706,6 +706,12 @@ private void CheckValidInstance() public Grpc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.AllowedHosts.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.AllowedHosts.cs index e87b09bb922..83d8a2c987d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.AllowedHosts.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.AllowedHosts.cs @@ -39,11 +39,13 @@ public readonly partial struct Http public readonly partial struct AllowedHosts #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public AllowedHosts Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.BrowserXssFilterEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.BrowserXssFilterEntity.cs index a24138aca0c..3f2821f72d0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.BrowserXssFilterEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.BrowserXssFilterEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public BrowserXssFilterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtection.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtection.cs index 46198683107..d79f34dbc3f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtection.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtection.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ClickjackingProtection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtectionFrameOptionsValue.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtectionFrameOptionsValue.cs index 29ef3bd0d75..8fbbe477b1a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtectionFrameOptionsValue.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ClickjackingProtectionFrameOptionsValue.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public ClickjackingProtectionFrameOptionsValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ContentSecurityPolicyCsp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ContentSecurityPolicyCsp.cs index 75df5a1d306..fa4687df117 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ContentSecurityPolicyCsp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ContentSecurityPolicyCsp.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public ContentSecurityPolicyCsp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.DevelopmentFlag.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.DevelopmentFlag.cs index 56c7aa5b9c0..051475cb586 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.DevelopmentFlag.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.DevelopmentFlag.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DevelopmentFlag Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ForceStsHeader.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ForceStsHeader.cs index b36177fe035..4f6b1dc63ca 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ForceStsHeader.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ForceStsHeader.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ForceStsHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HostsAreRegexps.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HostsAreRegexps.cs index 77ba7cbf5e0..66d58db8ba3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HostsAreRegexps.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HostsAreRegexps.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public HostsAreRegexps Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpPublicKeyPinningHpkp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpPublicKeyPinningHpkp.cs index 3956cba98bc..ca0b4899cb8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpPublicKeyPinningHpkp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpPublicKeyPinningHpkp.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public HttpPublicKeyPinningHpkp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpStrictTransportSecurityHstsSeconds.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpStrictTransportSecurityHstsSeconds.cs index a17e7d29bd0..37513d6189d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpStrictTransportSecurityHstsSeconds.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.HttpStrictTransportSecurityHstsSeconds.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public HttpStrictTransportSecurityHstsSeconds Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Mutable.cs index 5cb19105f50..2e984c3ba15 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Mutable.cs @@ -1459,6 +1459,106 @@ public bool RemoveStsSeconds() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowedHostsValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowedHostsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.AllowedHosts.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowedHostsAreRegexUtf8, out IJsonDocument? _, out int _)) + { + SetAllowedHostsAreRegex(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.HostsAreRegexps.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BrowserXssFilterUtf8, out IJsonDocument? _, out int _)) + { + SetBrowserXssFilter(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.BrowserXssFilterEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentSecurityPolicyUtf8, out IJsonDocument? _, out int _)) + { + SetContentSecurityPolicy(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.ContentSecurityPolicyCsp.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentTypeNosniffUtf8, out IJsonDocument? _, out int _)) + { + SetContentTypeNosniff(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.Nosniff.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CustomFrameOptionsValueUtf8, out IJsonDocument? _, out int _)) + { + SetCustomFrameOptionsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.ClickjackingProtectionFrameOptionsValue.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ForceStsHeaderValueUtf8, out IJsonDocument? _, out int _)) + { + SetForceStsHeaderValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.ForceStsHeader.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameDenyUtf8, out IJsonDocument? _, out int _)) + { + SetFrameDeny(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.ClickjackingProtection.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HpkpPublicKeyUtf8, out IJsonDocument? _, out int _)) + { + SetHpkpPublicKey(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.HttpPublicKeyPinningHpkp.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsDevelopmentUtf8, out IJsonDocument? _, out int _)) + { + SetIsDevelopment(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.DevelopmentFlag.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReferrerPolicyValueUtf8, out IJsonDocument? _, out int _)) + { + SetReferrerPolicyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.ReferrerPolicy.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SslHostValueUtf8, out IJsonDocument? _, out int _)) + { + SetSslHostValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.SslHost.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SslRedirectValueUtf8, out IJsonDocument? _, out int _)) + { + SetSslRedirectValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.SslRedirect.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StsIncludeSubdomainsUtf8, out IJsonDocument? _, out int _)) + { + SetStsIncludeSubdomains(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.StrictTransportSecurityIncludeSubdomains.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StsSecondsUtf8, out IJsonDocument? _, out int _)) + { + SetStsSeconds(Corvus.KrakendBenchmark.Current.KrakendSchema.Http.HttpStrictTransportSecurityHstsSeconds.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Nosniff.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Nosniff.cs index b0c73ff370e..41abe7557fd 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Nosniff.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.Nosniff.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Nosniff Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ReferrerPolicy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ReferrerPolicy.cs index 18a9d38561c..febb19870de 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ReferrerPolicy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.ReferrerPolicy.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ReferrerPolicy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslHost.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslHost.cs index 6131156262c..93e85f96d83 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslHost.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslHost.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public SslHost Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslRedirect.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslRedirect.cs index 4e3f20ecd3f..337ba9d5f60 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslRedirect.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.SslRedirect.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SslRedirect Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.StrictTransportSecurityIncludeSubdomains.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.StrictTransportSecurityIncludeSubdomains.cs index 991ae626c8b..1b05c2a65f4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.StrictTransportSecurityIncludeSubdomains.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.StrictTransportSecurityIncludeSubdomains.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public StrictTransportSecurityIncludeSubdomains Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.cs index f67aff24e9a..5197e5b300b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Http.cs @@ -819,6 +819,12 @@ private void CheckValidInstance() public Http Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.Mutable.cs index dbd757b8f3f..2ecc9ec25f8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.Mutable.cs @@ -452,6 +452,42 @@ public bool RemoveProxyAddress() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoRedirectValueUtf8, out IJsonDocument? _, out int _)) + { + SetNoRedirectValue(Corvus.KrakendBenchmark.Current.KrakendSchema.HttpClient.NoRedirect.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ClientTlsValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.Mutable __corvusClientTlsValue)) + { + __corvusClientTlsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.NoRedirect.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.NoRedirect.cs index da04718f415..2567a24dc87 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.NoRedirect.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.NoRedirect.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public NoRedirect Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.cs index 299f154a9f7..1103f5668ac 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpClient.cs @@ -478,6 +478,12 @@ private void CheckValidInstance() public HttpClient Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.Mutable.cs index 21ff5cc60c9..b105434705c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.Mutable.cs @@ -1145,6 +1145,84 @@ public bool RemoveWildcardValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NameUtf8, out IJsonDocument? _, out int _)) + { + SetName(Corvus.KrakendBenchmark.Current.KrakendSchema.HttpServer.PluginName.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GeoipValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Geoip.Mutable __corvusGeoipValue)) + { + __corvusGeoipValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IpFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.IpFilter.Mutable __corvusIpFilterValue)) + { + __corvusIpFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JwkAggregatorValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.JwkAggregator.Mutable __corvusJwkAggregatorValue)) + { + __corvusJwkAggregatorValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RedisRatelimitValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.RedisRatelimit.Mutable __corvusRedisRatelimitValue)) + { + __corvusRedisRatelimitValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StaticFilesystemUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.PluginStaticFilesystem.Mutable __corvusStaticFilesystem)) + { + __corvusStaticFilesystem.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UrlRewriteValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.UrlRewrite.Mutable __corvusUrlRewriteValue)) + { + __corvusUrlRewriteValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VirtualhostValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Virtualhost.Mutable __corvusVirtualhostValue)) + { + __corvusVirtualhostValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WildcardValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Wildcard.Mutable __corvusWildcardValue)) + { + __corvusWildcardValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.PluginName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.PluginName.cs index fab88de5e99..3245f041e7e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.PluginName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.PluginName.cs @@ -44,11 +44,13 @@ public readonly partial struct HttpServer public readonly partial struct PluginName #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public PluginName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.cs index 11651727ceb..3d5c6772a5c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.HttpServer.cs @@ -561,6 +561,12 @@ private void CheckValidInstance() public HttpServer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.DbName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.DbName.cs index 414131972c6..48a2f364675 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.DbName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.DbName.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public DbName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.Mutable.cs index 968e381fee5..c37e259b5c0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.Mutable.cs @@ -568,6 +568,36 @@ public bool RemoveUsername() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DbUtf8, out IJsonDocument? _, out int _)) + { + SetDb(Corvus.KrakendBenchmark.Current.KrakendSchema.Influx.DbName.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.PointsInBuffer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.PointsInBuffer.cs index f8ac9d5e81b..74632793106 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.PointsInBuffer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.PointsInBuffer.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public PointsInBuffer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.cs index 0e2583575c4..73d64463e8d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Influx.cs @@ -559,6 +559,12 @@ private void CheckValidInstance() public Influx Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.AllowOrDenyMode.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.AllowOrDenyMode.cs index 7547360b44e..a222912625f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.AllowOrDenyMode.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.AllowOrDenyMode.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AllowOrDenyMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.Mutable.cs index e8c79e7b06f..fa9d46b3106 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.Mutable.cs @@ -531,6 +531,36 @@ public bool RemoveTrustedProxies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowUtf8, out IJsonDocument? _, out int _)) + { + SetAllow(Corvus.KrakendBenchmark.Current.KrakendSchema.IpFilter.AllowOrDenyMode.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.cs index da1ea488206..4349ddd2fb7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.IpFilter.cs @@ -506,6 +506,12 @@ private void CheckValidInstance() public IpFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.Mutable.cs index 43110f8a037..a62aff9671e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.Mutable.cs @@ -226,6 +226,31 @@ public void SetExpr(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.cs index 4239afc90e0..872ad821547 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jmespath.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public Jmespath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.Mutable.cs index 5c1f9c26704..f9166c6b489 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.Mutable.cs @@ -226,6 +226,31 @@ public void SetSharedCacheDuration(scoped in Corvus.KrakendBenchmark.Current.Jso _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.cs index be18855ba63..7e3edac7b40 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Jose.cs @@ -425,6 +425,12 @@ private void CheckValidInstance() public Jose Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JsonStringArray.cs index f8d98adc207..efbee23b797 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JsonStringArray.cs @@ -26,11 +26,13 @@ public readonly partial struct KrakendSchema public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.Mutable.cs index 838ac18fc68..d76fc7d8a33 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.Mutable.cs @@ -389,6 +389,31 @@ public void SetPort(scoped in Corvus.KrakendBenchmark.Current.JsonInteger.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.cs index ef82d5d3f61..7edfcfc832a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.JwkAggregator.cs @@ -481,6 +481,12 @@ private void CheckValidInstance() public JwkAggregator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.MaxRetries.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.MaxRetries.cs index 058ae7db9e5..f7e40de9061 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.MaxRetries.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.MaxRetries.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaxRetries Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.Mutable.cs index 48ea6188baf..eaf93534a8a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.Mutable.cs @@ -517,6 +517,36 @@ public bool RemoveRegion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxRetriesValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxRetriesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Lambda.MaxRetries.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.cs index 091e94eae5c..06a94883485 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lambda.cs @@ -525,6 +525,12 @@ private void CheckValidInstance() public Lambda Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ListenIp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ListenIp.cs index afeec508ceb..06654e51bf3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ListenIp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ListenIp.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public ListenIp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogFormat.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogFormat.cs index 6808bb04b21..16d889f39b0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogFormat.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogFormat.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public LogFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogLevel.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogLevel.cs index dac881eed9e..28f1af0078b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogLevel.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogLevel.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public LogLevel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToStdout.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToStdout.cs index 0035e65a4bb..7b2ee9a21c1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToStdout.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToStdout.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public LogsToStdout Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToSyslog.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToSyslog.cs index 710e4d77010..cc17ed9a49c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToSyslog.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.LogsToSyslog.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public LogsToSyslog Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.Mutable.cs index bda7edfed34..2d8e929aa43 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.Mutable.cs @@ -652,6 +652,51 @@ public bool RemoveSyslogFacilityValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FormatUtf8, out IJsonDocument? _, out int _)) + { + SetFormat(Corvus.KrakendBenchmark.Current.KrakendSchema.Logging.LogFormat.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StdoutUtf8, out IJsonDocument? _, out int _)) + { + SetStdout(Corvus.KrakendBenchmark.Current.KrakendSchema.Logging.LogsToStdout.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SyslogUtf8, out IJsonDocument? _, out int _)) + { + SetSyslog(Corvus.KrakendBenchmark.Current.KrakendSchema.Logging.LogsToSyslog.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SyslogFacilityValueUtf8, out IJsonDocument? _, out int _)) + { + SetSyslogFacilityValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Logging.SyslogFacility.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.SyslogFacility.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.SyslogFacility.cs index 3d263065b06..ed20cc5a563 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.SyslogFacility.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.SyslogFacility.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SyslogFacility Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.cs index 4ad06ef2784..e998dcd102a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logging.cs @@ -584,6 +584,12 @@ private void CheckValidInstance() public Logging Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Enabled.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Enabled.cs index 0c6af433824..39942577178 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Enabled.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Enabled.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public Enabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Mutable.cs index da8bf5265c6..5904c045f38 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.Mutable.cs @@ -220,6 +220,36 @@ public void SetEnabledValue(scoped in Corvus.KrakendBenchmark.Current.KrakendSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledValueUtf8, out IJsonDocument? _, out int _)) + { + SetEnabledValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Logstash.Enabled.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.cs index 47d0edf7394..678cedc142a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Logstash.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public Logstash Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.LiveReload.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.LiveReload.cs index 72a9dca0e63..28c28c27ed0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.LiveReload.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.LiveReload.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public LiveReload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.Mutable.cs index d380bdfd71f..8fd090c1db2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.Mutable.cs @@ -798,6 +798,46 @@ public bool RemoveSources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowOpenLibsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowOpenLibs(Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.OpenExternalLibs.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LiveUtf8, out IJsonDocument? _, out int _)) + { + SetLive(Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.LiveReload.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipNextValueUtf8, out IJsonDocument? _, out int _)) + { + SetSkipNextValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.SkipNext.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.OpenExternalLibs.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.OpenExternalLibs.cs index 9c9a8336b8d..3be6e6f27ec 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.OpenExternalLibs.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.OpenExternalLibs.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public OpenExternalLibs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.SkipNext.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.SkipNext.cs index 902b66ab553..e8156f5cc5d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.SkipNext.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.SkipNext.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SkipNext Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.cs index d69e3c35321..737a3792e70 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Lua.cs @@ -644,6 +644,12 @@ private void CheckValidInstance() public Lua Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Mutable.cs index 7ea9372e69b..bfd70e7a315 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Mutable.cs @@ -414,6 +414,31 @@ public void SetValue(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Scope.cs index 7d6a05ef0bf..9e96d5b74cf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct AppendAHeader public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.cs index c17326475a5..aa4b2f2c5ee 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.AppendAHeader.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public AppendAHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.JsonStringArray.cs index 596d60e6783..c86ed0bee6e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct BlacklistHeaders public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Mutable.cs index 5fa5394776b..6a741c78d41 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Mutable.cs @@ -393,6 +393,31 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Scope.cs index 2e92f220d85..2fde09ff03c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct BlacklistHeaders public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.cs index 8b9d54e1fc3..62394ff91bb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BlacklistHeaders.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public BlacklistHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Mutable.cs index 16334c88b0b..98bb88f4ee0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Mutable.cs @@ -427,6 +427,31 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Scope.cs index 9895fd0dea0..21e5f0d9646 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct BodyModifier public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.cs index 7e50345905a..8595c8b858f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.BodyModifier.cs @@ -421,6 +421,12 @@ private void CheckValidInstance() public BodyModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Mutable.cs index c8c70caca46..8c68d508473 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Mutable.cs @@ -664,6 +664,43 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusElse)) + { + __corvusElse.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Scope.cs index d2a6b052d38..33181146f9f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct CookieFilter public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.cs index ed2d47cca0d..5d9d1c4cf4e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieFilter.cs @@ -476,6 +476,12 @@ private void CheckValidInstance() public CookieFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.HttpOnlyEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.HttpOnlyEntity.cs index b176a7ca2e9..a6ccbc86b60 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.HttpOnlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.HttpOnlyEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public HttpOnlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.MaxAgeEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.MaxAgeEntity.cs index 8d2b813f891..27a8515fafb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.MaxAgeEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.MaxAgeEntity.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public MaxAgeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Mutable.cs index 02c5b19184e..c7c92657496 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Mutable.cs @@ -810,6 +810,46 @@ public void SetValue(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HttpOnlyUtf8, out IJsonDocument? _, out int _)) + { + SetHttpOnly(Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.CookieModifier.HttpOnlyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxAgeUtf8, out IJsonDocument? _, out int _)) + { + SetMaxAge(Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.CookieModifier.MaxAgeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecureUtf8, out IJsonDocument? _, out int _)) + { + SetSecure(Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.CookieModifier.SecureEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Scope.cs index 79efb38013d..4f0d31e24a9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct CookieModifier public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.SecureEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.SecureEntity.cs index f72fcf2b7ab..0a4eddbe000 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.SecureEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.SecureEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SecureEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.cs index ae1715472b5..8ef3b6cfb17 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.CookieModifier.cs @@ -548,6 +548,12 @@ private void CheckValidInstance() public CookieModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.AggregateErrorsEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.AggregateErrorsEntity.cs index a8b6ec22a2a..9dbc9ce6d05 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.AggregateErrorsEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.AggregateErrorsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AggregateErrorsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.MartianArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.MartianArray.cs index 229610b4fee..91c9a3adeeb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.MartianArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.MartianArray.cs @@ -30,11 +30,13 @@ public readonly partial struct FifoGroup public readonly partial struct MartianArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public MartianArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Mutable.cs index d5ededa3a99..0bc44c32ead 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Mutable.cs @@ -459,6 +459,36 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AggregateErrorsUtf8, out IJsonDocument? _, out int _)) + { + SetAggregateErrors(Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.FifoGroup.AggregateErrorsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Scope.cs index 48a39967959..35ef19c8140 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct FifoGroup public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.cs index 95b3937ba2a..7e7a5332931 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.FifoGroup.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public FifoGroup Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Mutable.cs index f5970d6d5ee..cd067444168 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Mutable.cs @@ -414,6 +414,31 @@ public void SetTo(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Scope.cs index 0cb392b77ae..e8f03c18c64 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct HeaderCopy public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.cs index 46b016b80e1..a1724545779 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderCopy.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public HeaderCopy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Mutable.cs index 623274a563b..01ead67af0b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Mutable.cs @@ -628,6 +628,43 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusElse)) + { + __corvusElse.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Scope.cs index 69dc837d45b..4086e387aa4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct HeaderFilter public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.cs index 508a3d96e3a..4b61a600e2d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderFilter.cs @@ -476,6 +476,12 @@ private void CheckValidInstance() public HeaderFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Mutable.cs index 4e003f0dc5a..15d981f790b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Mutable.cs @@ -304,6 +304,31 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Scope.cs index 8e2492f414e..3576bf1a90e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct HeaderId public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.cs index 310258739e7..270ead7369c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderId.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public HeaderId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Mutable.cs index 8ea945f77b8..38b6e765a49 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Mutable.cs @@ -414,6 +414,31 @@ public void SetValue(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Scope.cs index f3d7574b475..b423c6d3a06 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct HeaderModifier public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.cs index 15c9fd16f1b..9b7efa91f63 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderModifier.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public HeaderModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Mutable.cs index 3df67ea61aa..ea02db59d03 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Mutable.cs @@ -509,6 +509,37 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Scope.cs index dcd76edb6f4..b55fcd415ba 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct HeaderRegexFilter public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.cs index 285352436c3..c2793bdc50d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.HeaderRegexFilter.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public HeaderRegexFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.Mutable.cs index 1e0199427a8..d14692d9e19 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.Mutable.cs @@ -2350,6 +2350,151 @@ public bool RemoveUrlRegexFilterValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BodyModifierValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.BodyModifier.Mutable __corvusBodyModifierValue)) + { + __corvusBodyModifierValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CookieFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.CookieFilter.Mutable __corvusCookieFilterValue)) + { + __corvusCookieFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CookieModifierValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.CookieModifier.Mutable __corvusCookieModifierValue)) + { + __corvusCookieModifierValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FifoGroupValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.FifoGroup.Mutable __corvusFifoGroupValue)) + { + __corvusFifoGroupValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderAppendUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.AppendAHeader.Mutable __corvusHeaderAppend)) + { + __corvusHeaderAppend.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderBlacklistUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.BlacklistHeaders.Mutable __corvusHeaderBlacklist)) + { + __corvusHeaderBlacklist.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderCopyValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.HeaderCopy.Mutable __corvusHeaderCopyValue)) + { + __corvusHeaderCopyValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.HeaderFilter.Mutable __corvusHeaderFilterValue)) + { + __corvusHeaderFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderIdValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.HeaderId.Mutable __corvusHeaderIdValue)) + { + __corvusHeaderIdValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderModifierValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.HeaderModifier.Mutable __corvusHeaderModifierValue)) + { + __corvusHeaderModifierValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderRegexFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.HeaderRegexFilter.Mutable __corvusHeaderRegexFilterValue)) + { + __corvusHeaderRegexFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PortFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.PortFilter.Mutable __corvusPortFilterValue)) + { + __corvusPortFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PortModifierValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.PortModifier.Mutable __corvusPortModifierValue)) + { + __corvusPortModifierValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PriorityGroupValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.PriorityGroup.Mutable __corvusPriorityGroupValue)) + { + __corvusPriorityGroupValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QuerystringFilterUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.QueryStringFilter.Mutable __corvusQuerystringFilter)) + { + __corvusQuerystringFilter.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QuerystringModifierValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.QuerystringModifier.Mutable __corvusQuerystringModifierValue)) + { + __corvusQuerystringModifierValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StashModifierValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.StashModifier.Mutable __corvusStashModifierValue)) + { + __corvusStashModifierValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UrlFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.UrlFilter.Mutable __corvusUrlFilterValue)) + { + __corvusUrlFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UrlModifierValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.UrlModifier.Mutable __corvusUrlModifierValue)) + { + __corvusUrlModifierValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UrlRegexFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.UrlRegexFilter.Mutable __corvusUrlRegexFilterValue)) + { + __corvusUrlRegexFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Mutable.cs index ef62c2ed9e0..25b7578828b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Mutable.cs @@ -562,6 +562,43 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusElse)) + { + __corvusElse.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Scope.cs index 1c21e5d919c..1e295d6b614 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct PortFilter public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.cs index f9051a50fb8..68ad53dd0d1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortFilter.cs @@ -455,6 +455,12 @@ private void CheckValidInstance() public PortFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Mutable.cs index dcfe62eeda2..484bd6804d2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Mutable.cs @@ -569,6 +569,31 @@ public bool RemoveScopeValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.Mutable.cs index aaaf9cddf1d..aeedf1e6b7b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.Mutable.cs @@ -388,6 +388,31 @@ public void SetScope(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.cs index cc508fea262..9327ab4c500 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredDefaultForSchemeAndScope.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public RequiredDefaultForSchemeAndScope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.Mutable.cs index 57f6d545ff8..81d6ff00de9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.Mutable.cs @@ -388,6 +388,31 @@ public void SetScope(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.cs index d751d6b9729..7fcfd9f4da3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredPortAndScope.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public RequiredPortAndScope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.Mutable.cs index 4c199240b69..dd772cadefc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.Mutable.cs @@ -388,6 +388,31 @@ public void SetScope(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.cs index 1d4cebd3e18..32ae3402083 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.RequiredRemoveEntityAndScope.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public RequiredRemoveEntityAndScope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Scope.cs index 147448a5cc4..0210c4ee48b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct PortModifier public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.cs index bcce62753dc..d1ebbdb856f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PortModifier.cs @@ -515,6 +515,12 @@ private void CheckValidInstance() public PortModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Mutable.cs index 8ce73c35477..fc384fab80a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Mutable.cs @@ -393,6 +393,31 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.Mutable.cs index 5c6930a5fc2..171217333d2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.Mutable.cs @@ -368,6 +368,37 @@ public void SetPriority(scoped in Corvus.KrakendBenchmark.Current.JsonInteger.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.cs index 96ccc77445a..29892c373f7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.RequiredModifierAndPriority.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public RequiredModifierAndPriority Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.cs index 1c21508ec99..1a3657eb1fe 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.RequiredModifierAndPriorityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct PriorityGroup public readonly partial struct RequiredModifierAndPriorityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RequiredModifierAndPriorityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Scope.cs index 0518abaa250..a44bbdf6577 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct PriorityGroup public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.cs index b5288a4ac01..a3e51473958 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.PriorityGroup.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public PriorityGroup Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Mutable.cs index 8a3db0b031a..6a2ea4adb8f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Mutable.cs @@ -628,6 +628,43 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusElse)) + { + __corvusElse.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Scope.cs index ab22a50d3df..cfdce950a74 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct QueryStringFilter public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.cs index be9f2d62be5..7f3df25c29e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QueryStringFilter.cs @@ -476,6 +476,12 @@ private void CheckValidInstance() public QueryStringFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Mutable.cs index dcd7389c5fc..415c1364766 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Mutable.cs @@ -414,6 +414,31 @@ public void SetValue(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Scope.cs index ba90e1f63ed..ce819a5d8fd 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct QuerystringModifier public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.cs index fb0449ef08e..b81356c8b99 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.QuerystringModifier.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public QuerystringModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Mutable.cs index 25979b17c93..c34b544fdab 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Mutable.cs @@ -359,6 +359,31 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Scope.cs index be88ca83954..8fc348176a1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct StashModifier public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.cs index 1196b852b1f..1b81b9ce4af 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.StashModifier.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public StashModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Mutable.cs index 84c054e0ef3..856703ed763 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Mutable.cs @@ -771,6 +771,43 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusElse)) + { + __corvusElse.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Scope.cs index a49e3ee3f63..4e3c61c7926 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct UrlFilter public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.cs index 7106e26a2be..35b1b9ab98d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlFilter.cs @@ -515,6 +515,12 @@ private void CheckValidInstance() public UrlFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Mutable.cs index 9f02e9c5b88..0cd9dec1a89 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Mutable.cs @@ -568,6 +568,31 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Scope.cs index ecbae6ec547..2eb0ea58e75 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct UrlModifier public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.cs index f1a57d3ab38..7684d2ebf9b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlModifier.cs @@ -458,6 +458,12 @@ private void CheckValidInstance() public UrlModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Mutable.cs index 80de102cb11..50cacc86619 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Mutable.cs @@ -562,6 +562,43 @@ public void SetScopeValue(in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusElse)) + { + __corvusElse.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Martian.Mutable __corvusModifier)) + { + __corvusModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Scope.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Scope.cs index 565f304bcd8..3ae10a7baaa 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Scope.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.Scope.cs @@ -30,11 +30,13 @@ public readonly partial struct UrlRegexFilter public readonly partial struct Scope #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public Scope Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.cs index afb98ec3fcc..e1e8b14f1d0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.UrlRegexFilter.cs @@ -455,6 +455,12 @@ private void CheckValidInstance() public UrlRegexFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.cs index 481d7675ae4..039fe15e680 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Martian.cs @@ -865,6 +865,12 @@ private void CheckValidInstance() public Martian Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxHeaderBytes.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxHeaderBytes.cs index 0e5455f2edb..b2b800818ae 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxHeaderBytes.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxHeaderBytes.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public MaxHeaderBytes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnections.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnections.cs index 9f96bf454e2..9053983d9a6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnections.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnections.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public MaxIdleConnections Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnectionsPerHost.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnectionsPerHost.cs index b60e677001e..bf619c4fec3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnectionsPerHost.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.MaxIdleConnectionsPerHost.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public MaxIdleConnectionsPerHost Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.BackendDisabled.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.BackendDisabled.cs index fe166758081..2bd59efb6d5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.BackendDisabled.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.BackendDisabled.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public BackendDisabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.EndpointDisabled.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.EndpointDisabled.cs index dab8b4fa7da..c7d27e0a180 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.EndpointDisabled.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.EndpointDisabled.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EndpointDisabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ListenAddress.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ListenAddress.cs index ea194dfca14..63cd42b1600 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ListenAddress.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ListenAddress.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ListenAddress Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.Mutable.cs index 4ac75da2b6e..f69ae86e12a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.Mutable.cs @@ -590,6 +590,56 @@ public bool RemoveRouterDisabledValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendDisabledValueUtf8, out IJsonDocument? _, out int _)) + { + SetBackendDisabledValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Metrics.BackendDisabled.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EndpointDisabledValueUtf8, out IJsonDocument? _, out int _)) + { + SetEndpointDisabledValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Metrics.EndpointDisabled.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ListenAddressValueUtf8, out IJsonDocument? _, out int _)) + { + SetListenAddressValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Metrics.ListenAddress.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProxyDisabledValueUtf8, out IJsonDocument? _, out int _)) + { + SetProxyDisabledValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Metrics.ProxyDisabled.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RouterDisabledValueUtf8, out IJsonDocument? _, out int _)) + { + SetRouterDisabledValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Metrics.RouterDisabled.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ProxyDisabled.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ProxyDisabled.cs index 0e6754e6faa..1bdfed2e1e2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ProxyDisabled.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.ProxyDisabled.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ProxyDisabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.RouterDisabled.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.RouterDisabled.cs index fcb4a1a66ef..1b36141f8ff 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.RouterDisabled.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.RouterDisabled.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public RouterDisabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.cs index 6eb9753f4c8..7bab5b10ba3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Metrics.cs @@ -553,6 +553,12 @@ private void CheckValidInstance() public Metrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.BatchSize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.BatchSize.cs index 2873fada230..306c2f7039b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.BatchSize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.BatchSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public BatchSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EnableDebug.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EnableDebug.cs index 44d56bebc62..5189d136aee 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EnableDebug.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EnableDebug.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EnableDebug Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EventQueueSize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EventQueueSize.cs index 31562931147..42284bfc32b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EventQueueSize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.EventQueueSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public EventQueueSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.Mutable.cs index 9c7dba91a06..940a2be0b45 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.Mutable.cs @@ -379,6 +379,31 @@ public bool RemoveQueryString() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.cs index 5949de06f23..b275ead83fa 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.IdentifyCompany.cs @@ -477,6 +477,12 @@ private void CheckValidInstance() public IdentifyCompany Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.JsonStringArray.cs index 408b2acbb47..d84cfa7e8ac 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Moesif public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.Mutable.cs index f7b2ada87d4..723d69fc279 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.Mutable.cs @@ -1375,6 +1375,72 @@ public bool RemoveUserIdJwtClaimValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BatchSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetBatchSizeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.BatchSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.EnableDebug.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EventQueueSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetEventQueueSizeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.EventQueueSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LogBodyUtf8, out IJsonDocument? _, out int _)) + { + SetLogBody(Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.SendTheBody.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShouldSkipValueUtf8, out IJsonDocument? _, out int _)) + { + SetShouldSkipValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.ShouldSkip.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TimerWakeUpSecondsUtf8, out IJsonDocument? _, out int _)) + { + SetTimerWakeUpSeconds(Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.TimerWakeUp.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UserIdJwtClaimValueUtf8, out IJsonDocument? _, out int _)) + { + SetUserIdJwtClaimValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.UserIdJwtClaim.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IdentifyCompanyValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.IdentifyCompany.Mutable __corvusIdentifyCompanyValue)) + { + __corvusIdentifyCompanyValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.RequestHeaArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.RequestHeaArray.cs index 3942b4dfcd9..5537feb84ee 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.RequestHeaArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.RequestHeaArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Moesif public readonly partial struct RequestHeaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public RequestHeaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseBoArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseBoArray.cs index 72025e53721..ceff9a46cd0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseBoArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseBoArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Moesif public readonly partial struct ResponseBoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public ResponseBoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseHeArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseHeArray.cs index 23589ce6036..a03ddcfebf5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseHeArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ResponseHeArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Moesif public readonly partial struct ResponseHeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public ResponseHeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.SendTheBody.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.SendTheBody.cs index ce005d7f52c..962c76a886f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.SendTheBody.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.SendTheBody.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SendTheBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ShouldSkip.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ShouldSkip.cs index f251da9eeca..03236e348ff 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ShouldSkip.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.ShouldSkip.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public ShouldSkip Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.TimerWakeUp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.TimerWakeUp.cs index 05f0f36e1bc..1baacd094d5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.TimerWakeUp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.TimerWakeUp.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public TimerWakeUp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.UserIdJwtClaim.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.UserIdJwtClaim.cs index 36d79f9b1bf..59eb8e093a2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.UserIdJwtClaim.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.UserIdJwtClaim.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public UserIdJwtClaim Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.cs index 4637434c704..1568e9fc65d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Moesif.cs @@ -756,6 +756,12 @@ private void CheckValidInstance() public Moesif Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Mutable.cs index a7b8c0f7f23..3ab075ad629 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Mutable.cs @@ -2862,6 +2862,125 @@ public bool RemoveWriteTimeout() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugEndpointValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugEndpointValue(Corvus.KrakendBenchmark.Current.KrakendSchema.DebugEndpoint.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableCompressionValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableCompressionValue(Corvus.KrakendBenchmark.Current.KrakendSchema.DisableCompression.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableKeepAlivesValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableKeepAlivesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.DisableKeepAlives.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableRestUtf8, out IJsonDocument? _, out int _)) + { + SetDisableRest(Corvus.KrakendBenchmark.Current.KrakendSchema.DisableResTfulUrLs.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EchoEndpointValueUtf8, out IJsonDocument? _, out int _)) + { + SetEchoEndpointValue(Corvus.KrakendBenchmark.Current.KrakendSchema.EchoEndpoint.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ListenIpValueUtf8, out IJsonDocument? _, out int _)) + { + SetListenIpValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ListenIp.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxHeaderBytesValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxHeaderBytesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.MaxHeaderBytes.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxIdleConnectionsValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxIdleConnectionsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.MaxIdleConnections.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxIdleConnectionsPerHostValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxIdleConnectionsPerHostValue(Corvus.KrakendBenchmark.Current.KrakendSchema.MaxIdleConnectionsPerHost.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NameValueUtf8, out IJsonDocument? _, out int _)) + { + SetNameValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Name.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputEncodingValueUtf8, out IJsonDocument? _, out int _)) + { + SetOutputEncodingValue(Corvus.KrakendBenchmark.Current.KrakendSchema.OutputEncoding.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PortValueUtf8, out IJsonDocument? _, out int _)) + { + SetPortValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Port.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SequentialStartValueUtf8, out IJsonDocument? _, out int _)) + { + SetSequentialStartValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SequentialStart.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseH2cUtf8, out IJsonDocument? _, out int _)) + { + SetUseH2c(Corvus.KrakendBenchmark.Current.KrakendSchema.EnableH2c.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ClientTlsValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ClientTls.Mutable __corvusClientTlsValue)) + { + __corvusClientTlsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtraConfigUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ServiceExtraConfig.Mutable __corvusExtraConfig)) + { + __corvusExtraConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Plugin.Mutable __corvusPluginValue)) + { + __corvusPluginValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TlsValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.Mutable __corvusTlsValue)) + { + __corvusTlsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Name.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Name.cs index 912ec88232b..f423d53a0a8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Name.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Name.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.EnableDebug.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.EnableDebug.cs index fb5c2af5db2..ca9fbea8f47 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.EnableDebug.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.EnableDebug.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EnableDebug Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.Mutable.cs index 79d77f979d4..dfac1967f41 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.Mutable.cs @@ -402,6 +402,36 @@ public void SetLicense(scoped in Corvus.KrakendBenchmark.Current.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Newrelic.EnableDebug.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.cs index 1c3a837d298..c50e7d688a4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Newrelic.cs @@ -478,6 +478,12 @@ private void CheckValidInstance() public Newrelic Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.Mutable.cs index 8fd04849320..dfbd49b8014 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.Mutable.cs @@ -285,6 +285,31 @@ public void SetUser(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.cs index 8f1172f6714..77c5cdd49ac 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Ntlm.cs @@ -456,6 +456,12 @@ private void CheckValidInstance() public Ntlm Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.JsonSchemaEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.JsonSchemaEntity.cs index 73c3fd1a402..d544ce6030e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.JsonSchemaEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.JsonSchemaEntity.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public JsonSchemaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.cs index 9f7454df3ed..f0d6f399c1f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ComponentSchemas.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public ComponentSchemas Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ContentType.cs index f3fac460b9c..1ff4feede09 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ContentType.cs @@ -611,6 +611,12 @@ private void CheckValidInstance() public ContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ExampleSchemaEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ExampleSchemaEntity.cs index b4c6401ad04..12973dcd646 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ExampleSchemaEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.ExampleSchemaEntity.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public ExampleSchemaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.Mutable.cs index 42498e59d08..584ae37907b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.Mutable.cs @@ -572,6 +572,31 @@ public bool RemoveRef() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.cs index 8a90242422c..b033f15bee5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.RequiredContentType.cs @@ -514,6 +514,12 @@ private void CheckValidInstance() public RequiredContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.cs index e21b9d89e6f..2294b759b6f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.DefinitionOfErrorsOas3Only.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public DefinitionOfErrorsOas3Only Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Example.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Example.cs index 58fc4b7df3b..bf2b080d1c7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Example.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Example.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public Example Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.JwtKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.JwtKey.cs index 0769ec7ebbe..12c7a956076 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.JwtKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.JwtKey.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public JwtKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Mutable.cs index 5252a85208b..e70d6aa8b10 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.Mutable.cs @@ -2131,6 +2131,41 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JwtKeyValueUtf8, out IJsonDocument? _, out int _)) + { + SetJwtKeyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Openapi.JwtKey.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SchemesUtf8, out IJsonDocument? _, out int _)) + { + SetSchemes(Corvus.KrakendBenchmark.Current.KrakendSchema.Openapi.SupportedSchemes.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.Mutable.cs index 899ba91163e..2f8fde39c5e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.Mutable.cs @@ -294,6 +294,31 @@ public void SetName(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.cs index b3e9c30d5ad..86682d5540f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.Parameters.cs @@ -443,6 +443,12 @@ private void CheckValidInstance() public Parameters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.cs index dfba4d512ab..fa645bda0cf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.ParametersArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Openapi public readonly partial struct ParametersArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public ParametersArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.Mutable.cs index e5cf5534076..a8c2186ff52 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.Mutable.cs @@ -361,6 +361,31 @@ public bool RemoveRequired() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.cs index d53af72965c..7878c444992 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.QueryStrings.cs @@ -465,6 +465,12 @@ private void CheckValidInstance() public QueryStrings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.cs index 7289f721e3a..32d9e4cdf6b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.QueryStringsArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Openapi public readonly partial struct QueryStringsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public QueryStringsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ContentType.cs index d5c4ea06b86..7101c41537c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ContentType.cs @@ -611,6 +611,12 @@ private void CheckValidInstance() public ContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ExampleSchemaEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ExampleSchemaEntity.cs index 1828f5ec7e5..a7ebb0cc624 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ExampleSchemaEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.ExampleSchemaEntity.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public ExampleSchemaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.Mutable.cs index 1a324a5622e..b0cd83d572f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.Mutable.cs @@ -572,6 +572,31 @@ public bool RemoveRef() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.cs index 5e23acad56e..c78d7bd77f9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.RequiredContentType.cs @@ -514,6 +514,12 @@ private void CheckValidInstance() public RequiredContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.cs index 4154815b369..2f5ed464235 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.RequiredContentTypeArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Openapi public readonly partial struct RequiredContentTypeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public RequiredContentTypeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.SupportedSchemes.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.SupportedSchemes.cs index da0c9ba1297..a2a7d71c1a8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.SupportedSchemes.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.SupportedSchemes.cs @@ -39,11 +39,13 @@ public readonly partial struct Openapi public readonly partial struct SupportedSchemes #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public SupportedSchemes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.Mutable.cs index 7aaf07f43ff..638d6b0fd96 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.Mutable.cs @@ -294,6 +294,31 @@ public void SetName(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.cs index a01c3cd7d50..4386a3a32b7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.Tags.cs @@ -443,6 +443,12 @@ private void CheckValidInstance() public Tags Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.cs index c29c562faf0..3f934f627e9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.TagsArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Openapi public readonly partial struct TagsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public TagsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.cs index 7039a1cf61b..73bf5d6ba3f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Openapi.cs @@ -969,6 +969,12 @@ private void CheckValidInstance() public Openapi Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.Mutable.cs index 6cb76ea5eb3..11d5db39485 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.Mutable.cs @@ -370,6 +370,46 @@ public bool RemoveRouter() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendUtf8, out IJsonDocument? _, out int _)) + { + SetBackend(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.EnabledLayers.ReportBackend.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PipeUtf8, out IJsonDocument? _, out int _)) + { + SetPipe(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.EnabledLayers.ReportPipe.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RouterUtf8, out IJsonDocument? _, out int _)) + { + SetRouter(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.EnabledLayers.ReportRouter.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportBackend.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportBackend.cs index 554847013fe..67c4bc39628 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportBackend.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportBackend.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ReportBackend Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportPipe.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportPipe.cs index e75dcc8dd71..03d57d38332 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportPipe.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportPipe.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ReportPipe Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportRouter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportRouter.cs index 9ec791003f0..742770184a3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportRouter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.ReportRouter.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ReportRouter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.cs index d38c75e87cd..ae7ee6d3cb4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.EnabledLayers.cs @@ -465,6 +465,12 @@ private void CheckValidInstance() public EnabledLayers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Mutable.cs index 1be4f93d8ef..53b1dddff49 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Mutable.cs @@ -535,6 +535,41 @@ public void SetVersionValue(scoped in Corvus.KrakendBenchmark.Current.KrakendSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseEnvValueUtf8, out IJsonDocument? _, out int _)) + { + SetUseEnvValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.AwsXRay.UseEnv.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionValueUtf8, out IJsonDocument? _, out int _)) + { + SetVersionValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.AwsXRay.Version.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.Mutable.cs index 361436cb161..4d0d43b5276 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.Mutable.cs @@ -562,6 +562,31 @@ public void SetVersion(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.cs index e3479dba007..ce4bd52c6e4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion.cs @@ -429,6 +429,12 @@ private void CheckValidInstance() public RequiredAccessKeyIdAndRegionAndSecretAccessKeyAndVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.Mutable.cs index 0c1c2f7c4fd..b38cbf6823e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.Mutable.cs @@ -476,6 +476,31 @@ public void SetVersion(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.cs index 368a07980b3..0a7589f30cc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.RequiredRegionAndUseEnvAndVersion.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public RequiredRegionAndUseEnvAndVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.UseEnv.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.UseEnv.cs index 92df4d6a88b..7fa8c723628 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.UseEnv.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.UseEnv.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public UseEnv Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Version.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Version.cs index aaa21acbb4c..b6bb933aea1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Version.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.Version.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public Version Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.cs index 90021ae27ad..f54dde02ea4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.AwsXRay.cs @@ -586,6 +586,12 @@ private void CheckValidInstance() public AwsXRay Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.DisableCountPerBuckets.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.DisableCountPerBuckets.cs index dd82211bf57..a0ac7208cac 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.DisableCountPerBuckets.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.DisableCountPerBuckets.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableCountPerBuckets Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.Mutable.cs index 9506985c3d9..4f078c3ac2e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.Mutable.cs @@ -652,6 +652,46 @@ public void SetTraceAddressValue(scoped in Corvus.KrakendBenchmark.Current.Krake _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableCountPerBucketsValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableCountPerBucketsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Datadog.DisableCountPerBuckets.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatsAddressValueUtf8, out IJsonDocument? _, out int _)) + { + SetStatsAddressValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Datadog.StatsAddress.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TraceAddressValueUtf8, out IJsonDocument? _, out int _)) + { + SetTraceAddressValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Datadog.TraceAddress.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.StatsAddress.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.StatsAddress.cs index 8258b536f4d..2a5b01b5cd6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.StatsAddress.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.StatsAddress.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public StatsAddress Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.TraceAddress.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.TraceAddress.cs index 79e5e04113f..6fd466fd6b0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.TraceAddress.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.TraceAddress.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TraceAddress Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.cs index c86b8b38820..3bfc44793ed 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Datadog.cs @@ -600,6 +600,12 @@ private void CheckValidInstance() public Datadog Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.Mutable.cs index 7c37516ec0c..b438b953662 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.Mutable.cs @@ -502,6 +502,31 @@ public bool RemoveUsername() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.cs index 2a1d888c76d..923b25adbb9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Influxdb.cs @@ -538,6 +538,12 @@ private void CheckValidInstance() public Influxdb Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.Mutable.cs index 0f1c9ebd092..ca25a0f9240 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.Mutable.cs @@ -487,6 +487,31 @@ public bool RemoveServiceName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.Mutable.cs index d3e7a3837a8..46da54329b5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.Mutable.cs @@ -390,6 +390,31 @@ public void SetServiceName(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.cs index 590158917ab..6938b6065a6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredAgentEndpointAndServiceName.cs @@ -387,6 +387,12 @@ private void CheckValidInstance() public RequiredAgentEndpointAndServiceName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.Mutable.cs index f5451ae9b12..20c56b30114 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.Mutable.cs @@ -390,6 +390,31 @@ public void SetServiceName(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.cs index 32d1587f599..f7168f017e2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.RequiredEndpointAndServiceName.cs @@ -387,6 +387,12 @@ private void CheckValidInstance() public RequiredEndpointAndServiceName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.cs index 169ba01cf2f..31a5a96180c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Jaeger.cs @@ -558,6 +558,12 @@ private void CheckValidInstance() public Jaeger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Mutable.cs index 138a116f746..9f455c71bff 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Mutable.cs @@ -305,6 +305,41 @@ public bool RemoveStatsValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpansValueUtf8, out IJsonDocument? _, out int _)) + { + SetSpansValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Logger.Spans.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatsValueUtf8, out IJsonDocument? _, out int _)) + { + SetStatsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Logger.Stats.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Spans.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Spans.cs index 5a16e6448bf..98d77803b4f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Spans.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Spans.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Spans Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Stats.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Stats.cs index 932b976f9f1..b2bf048b4d3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Stats.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.Stats.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Stats Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.cs index a60656c1366..8f62a9ebb40 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Logger.cs @@ -448,6 +448,12 @@ private void CheckValidInstance() public Logger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Mutable.cs index 401390b4de7..b251fd5b611 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Mutable.cs @@ -1111,6 +1111,85 @@ public bool RemoveZipkinValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DatadogValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Datadog.Mutable __corvusDatadogValue)) + { + __corvusDatadogValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InfluxdbValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Influxdb.Mutable __corvusInfluxdbValue)) + { + __corvusInfluxdbValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JaegerValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Jaeger.Mutable __corvusJaegerValue)) + { + __corvusJaegerValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LoggerValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Logger.Mutable __corvusLoggerValue)) + { + __corvusLoggerValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OcagentValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Ocagent.Mutable __corvusOcagentValue)) + { + __corvusOcagentValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrometheusValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Prometheus.Mutable __corvusPrometheusValue)) + { + __corvusPrometheusValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StackdriverValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Stackdriver.Mutable __corvusStackdriverValue)) + { + __corvusStackdriverValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.XrayUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.AwsXRay.Mutable __corvusXray)) + { + __corvusXray.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ZipkinValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Zipkin.Mutable __corvusZipkinValue)) + { + __corvusZipkinValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.EnableCompression.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.EnableCompression.cs index 6b7ac99eafd..f34f7a2471d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.EnableCompression.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.EnableCompression.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public EnableCompression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Insecure.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Insecure.cs index 5bef83169d5..0eb04e6986c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Insecure.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Insecure.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public Insecure Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Mutable.cs index 084bc1b7b77..03df485c2b5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.Mutable.cs @@ -608,6 +608,41 @@ public void SetServiceName(scoped in Corvus.KrakendBenchmark.Current.JsonString. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableCompressionValueUtf8, out IJsonDocument? _, out int _)) + { + SetEnableCompressionValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Ocagent.EnableCompression.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InsecureValueUtf8, out IJsonDocument? _, out int _)) + { + SetInsecureValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Ocagent.Insecure.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.cs index 1dc74dd3249..1f5dbcf062a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Ocagent.cs @@ -563,6 +563,12 @@ private void CheckValidInstance() public Ocagent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.Mutable.cs index 8bf6b5ff1c7..ac0832cc78b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.Mutable.cs @@ -580,6 +580,51 @@ public bool RemoveTagStatuscode() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagHostValueUtf8, out IJsonDocument? _, out int _)) + { + SetTagHostValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Prometheus.TagHost.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagMethodValueUtf8, out IJsonDocument? _, out int _)) + { + SetTagMethodValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Prometheus.TagMethod.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagPathValueUtf8, out IJsonDocument? _, out int _)) + { + SetTagPathValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Prometheus.TagPath.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagStatuscodeUtf8, out IJsonDocument? _, out int _)) + { + SetTagStatuscode(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Prometheus.TagStatusCode.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagHost.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagHost.cs index ceb59962fba..8fef6041ecd 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagHost.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagHost.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TagHost Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagMethod.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagMethod.cs index 84b7d9b2a1f..78e3106282d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagMethod.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagMethod.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TagMethod Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagPath.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagPath.cs index 3de124fa1da..f10747f14ed 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagPath.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagPath.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TagPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagStatusCode.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagStatusCode.cs index 28e68977e1d..be12e7f6a95 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagStatusCode.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.TagStatusCode.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TagStatusCode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.cs index b6c470d2062..a45bb0a84d9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Prometheus.cs @@ -554,6 +554,12 @@ private void CheckValidInstance() public Prometheus Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.Mutable.cs index 03666f75de2..28b64782ca1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.Mutable.cs @@ -393,6 +393,36 @@ public void SetProjectIdValue(scoped in Corvus.KrakendBenchmark.Current.KrakendS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProjectIdValueUtf8, out IJsonDocument? _, out int _)) + { + SetProjectIdValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Stackdriver.ProjectId.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.ProjectId.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.ProjectId.cs index 8452e26acc5..599de8ca4a7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.ProjectId.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.ProjectId.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public ProjectId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.cs index 421a64b6e97..65f6e09ab53 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Stackdriver.cs @@ -482,6 +482,12 @@ private void CheckValidInstance() public Stackdriver Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.Mutable.cs index cd300f31878..96f3a6d5941 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.Mutable.cs @@ -289,6 +289,31 @@ public void SetServiceName(scoped in Corvus.KrakendBenchmark.Current.JsonString. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.cs index 79df34683b2..edf3fbbd7cb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.Zipkin.cs @@ -457,6 +457,12 @@ private void CheckValidInstance() public Zipkin Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.cs index 1ee3b8e64e1..80a08d6f02e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Exporters.cs @@ -612,6 +612,12 @@ private void CheckValidInstance() public Exporters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Mutable.cs index 5e855df99fd..e63f9b40b91 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.Mutable.cs @@ -500,6 +500,53 @@ public bool RemoveSampleRateValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReportingPeriodValueUtf8, out IJsonDocument? _, out int _)) + { + SetReportingPeriodValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.ReportingPeriod.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SampleRateValueUtf8, out IJsonDocument? _, out int _)) + { + SetSampleRateValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.SampleRate.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledLayersValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.EnabledLayers.Mutable __corvusEnabledLayersValue)) + { + __corvusEnabledLayersValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExportersValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Exporters.Mutable __corvusExportersValue)) + { + __corvusExportersValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.ReportingPeriod.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.ReportingPeriod.cs index 3e7ec160309..496f782138d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.ReportingPeriod.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.ReportingPeriod.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ReportingPeriod Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.SampleRate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.SampleRate.cs index 7e9df897912..2842b170889 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.SampleRate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.SampleRate.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public SampleRate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.cs index 997f2f8b120..c96a64ba6cf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opencensus.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public Opencensus Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.Mutable.cs index a2e57511d02..15b1b04129d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.Mutable.cs @@ -381,6 +381,31 @@ public bool RemovePrometheus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableMetrics.cs index b36a95cc9ab..bdad4dce4f9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableMetrics.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DisableMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableTraces.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableTraces.cs index 6dd12743a07..16e6dc7adb1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableTraces.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableTraces.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DisableTraces Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Mutable.cs index aa522004e32..7f0ac6671ae 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Mutable.cs @@ -571,6 +571,46 @@ public bool RemoveUseHttp() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMetricsValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMetricsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableTracesValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableTracesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.DisableTraces.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PortValueUtf8, out IJsonDocument? _, out int _)) + { + SetPortValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Port.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Port.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Port.cs index 3278fecfa9a..de2f5e60597 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Port.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.Port.cs @@ -421,6 +421,12 @@ private void CheckValidInstance() public Port Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.cs index 5e99932ee34..dd4cb3d84c6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.RequiredHostAndName.cs @@ -554,6 +554,12 @@ private void CheckValidInstance() public RequiredHostAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.cs index c43fc5aa98a..b33031cc666 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredHostAndNameArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Exporters public readonly partial struct RequiredHostAndNameArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public RequiredHostAndNameArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.DisableMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.DisableMetrics.cs index c5fe3370ccf..673dfb2344b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.DisableMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.DisableMetrics.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DisableMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.ListenIp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.ListenIp.cs index 86140adf4b6..07f8173cc39 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.ListenIp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.ListenIp.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public ListenIp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Mutable.cs index bbe029dd615..850249604b5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Mutable.cs @@ -579,6 +579,46 @@ public bool RemoveProcessMetrics() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMetricsValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMetricsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.DisableMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ListenIpValueUtf8, out IJsonDocument? _, out int _)) + { + SetListenIpValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.ListenIp.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PortValueUtf8, out IJsonDocument? _, out int _)) + { + SetPortValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Port.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Port.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Port.cs index 7b7d27db411..720301a2ba3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Port.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.Port.cs @@ -421,6 +421,12 @@ private void CheckValidInstance() public Port Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.cs index 2193dd86582..b0e60487b4f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.RequiredName.cs @@ -548,6 +548,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.cs index 7312bfee131..2e3e4e220ed 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.RequiredNameArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Exporters public readonly partial struct RequiredNameArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public RequiredNameArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.cs index 8fb689deb39..26f8cfc201b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Exporters.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public Exporters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.JsonStringArray.cs index 314a45da480..c7d1c8ff878 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.JsonStringArray.cs @@ -44,11 +44,13 @@ public readonly partial struct Opentelemetry public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -99,6 +101,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -312,6 +329,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.Mutable.cs index eea2ada5e7f..13a8ef1e108 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.Mutable.cs @@ -487,6 +487,49 @@ public bool RemoveProxy() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.Mutable __corvusBackend)) + { + __corvusBackend.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GlobalUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.Mutable __corvusGlobal)) + { + __corvusGlobal.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProxyUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.Mutable __corvusProxy)) + { + __corvusProxy.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedHttpConnectionMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedHttpConnectionMetrics.cs index d5c45d7e9d7..47c7fc90352 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedHttpConnectionMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedHttpConnectionMetrics.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DetailedHttpConnectionMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedPayloadRead.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedPayloadRead.cs index 3abb9b90806..515e929f936 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedPayloadRead.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedPayloadRead.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DetailedPayloadRead Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedRoundTrip.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedRoundTrip.cs index e58025c53c4..fe14703fb6e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedRoundTrip.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedRoundTrip.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DetailedRoundTrip Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DisableThisStage.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DisableThisStage.cs index 4af709d93f6..2dda6118440 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DisableThisStage.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DisableThisStage.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DisableThisStage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.Mutable.cs index 35c10f85ed5..d1a0f76ce84 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.Mutable.cs @@ -559,6 +559,51 @@ public bool RemoveStaticAttributes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DetailedConnectionUtf8, out IJsonDocument? _, out int _)) + { + SetDetailedConnection(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedHttpConnectionMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableStageUtf8, out IJsonDocument? _, out int _)) + { + SetDisableStage(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DisableThisStage.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReadPayloadUtf8, out IJsonDocument? _, out int _)) + { + SetReadPayload(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedPayloadRead.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoundTripUtf8, out IJsonDocument? _, out int _)) + { + SetRoundTrip(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.DetailedRoundTrip.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs index c7bab31677e..899b56cce5b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs @@ -295,6 +295,31 @@ public void SetValue(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs index b743c90482d..e974fb5d6ec 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs @@ -458,6 +458,12 @@ private void CheckValidInstance() public RequiredKeyAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.cs index 9e491c5433c..6b390574db2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.RequiredKeyAndValueArray.cs @@ -37,11 +37,13 @@ public readonly partial struct MetricsEntity public readonly partial struct RequiredKeyAndValueArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public RequiredKeyAndValueArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.cs index 8de04a425df..14bb21b55ed 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.cs @@ -523,6 +523,12 @@ private void CheckValidInstance() public MetricsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.Mutable.cs index f6d57fee68e..b177a4f45f4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.Mutable.cs @@ -365,6 +365,43 @@ public bool RemoveTraces() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetricsUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.MetricsEntity.Mutable __corvusMetrics)) + { + __corvusMetrics.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TracesUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.Mutable __corvusTraces)) + { + __corvusTraces.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedHttpConnection.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedHttpConnection.cs index cf1fced94bc..d61ae9fb735 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedHttpConnection.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedHttpConnection.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DetailedHttpConnection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedPayloadRead.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedPayloadRead.cs index b451dc1f393..86c12ac9856 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedPayloadRead.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedPayloadRead.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DetailedPayloadRead Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedRoundTrip.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedRoundTrip.cs index d54b57b2f69..b5b129d2f93 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedRoundTrip.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedRoundTrip.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DetailedRoundTrip Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DisableThisStage.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DisableThisStage.cs index 39304882abb..5bd3722193f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DisableThisStage.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DisableThisStage.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public DisableThisStage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.Mutable.cs index ca4ed2252f2..44a01ce1f00 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.Mutable.cs @@ -629,6 +629,56 @@ public bool RemoveStaticAttributes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DetailedConnectionUtf8, out IJsonDocument? _, out int _)) + { + SetDetailedConnection(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedHttpConnection.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableStageUtf8, out IJsonDocument? _, out int _)) + { + SetDisableStage(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DisableThisStage.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReadPayloadUtf8, out IJsonDocument? _, out int _)) + { + SetReadPayload(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedPayloadRead.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReportHeadersValueUtf8, out IJsonDocument? _, out int _)) + { + SetReportHeadersValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.ReportHeaders.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoundTripUtf8, out IJsonDocument? _, out int _)) + { + SetRoundTrip(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.DetailedRoundTrip.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.ReportHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.ReportHeaders.cs index 1cafb845340..9d57ea355d6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.ReportHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.ReportHeaders.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public ReportHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs index 00a0eba7801..491f85026b5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs @@ -295,6 +295,31 @@ public void SetValue(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs index 240e42f56af..533c6b1178a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs @@ -458,6 +458,12 @@ private void CheckValidInstance() public RequiredKeyAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.cs index a732942076e..7fb78e787c7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.RequiredKeyAndValueArray.cs @@ -37,11 +37,13 @@ public readonly partial struct TracesEntity public readonly partial struct RequiredKeyAndValueArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public RequiredKeyAndValueArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.cs index 92771b484cf..4b795cb6f56 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.TracesEntity.cs @@ -548,6 +548,12 @@ private void CheckValidInstance() public TracesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.cs index 7bf9f16bf85..baa01f2bc6a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportBackendActivity.cs @@ -436,6 +436,12 @@ private void CheckValidInstance() public ReportBackendActivity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalMetrics.cs index 8fbb54853c9..99b857e0b52 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalMetrics.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableGlobalMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalTrace.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalTrace.cs index 6cb91a0cffe..0ffc1c7fbb3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalTrace.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalTrace.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableGlobalTrace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisablePropagation.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisablePropagation.cs index 3317a2bfb7e..54b667163e8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisablePropagation.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisablePropagation.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisablePropagation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs index a8dde5b4a05..d5aff6475eb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs index a722be4d5c9..24e2fb76232 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MetricsStaticAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.cs index 62f0423a189..53483990dd6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.MetricsStaticAttributesEntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct ReportGlobalActivity public readonly partial struct MetricsStaticAttributesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public MetricsStaticAttributesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.Mutable.cs index 2bcc9efd8c7..de203321f7b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.Mutable.cs @@ -657,6 +657,51 @@ public bool RemoveTracesStaticAttributes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMetricsUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMetrics(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisablePropagationValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisablePropagationValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisablePropagation.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableTracesUtf8, out IJsonDocument? _, out int _)) + { + SetDisableTraces(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.DisableGlobalTrace.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReportHeadersValueUtf8, out IJsonDocument? _, out int _)) + { + SetReportHeadersValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.ReportHeaders.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.ReportHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.ReportHeaders.cs index 7d167d6217c..152457e0758 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.ReportHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.ReportHeaders.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public ReportHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs index 9048f288f91..86718acfc1d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs index f2512e71f5c..35855c19fb9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public TracesStaticAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.cs index 53abbf75da2..1db05addf7b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.TracesStaticAttributesEntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct ReportGlobalActivity public readonly partial struct TracesStaticAttributesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public TracesStaticAttributesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.cs index 8c1d8c0f184..796e573332c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportGlobalActivity.cs @@ -548,6 +548,12 @@ private void CheckValidInstance() public ReportGlobalActivity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyMetrics.cs index 90250329f63..da91a91a63f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyMetrics.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableProxyMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyTrace.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyTrace.cs index 0582f125bb0..f64b85529d7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyTrace.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyTrace.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableProxyTrace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs index c71f66de3ce..b8fbd10460c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs index f411579fe5e..9745cd9c68f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.MetricsStaticAttributesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MetricsStaticAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.cs index 3f153dbec21..a8e6f0f44d5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.MetricsStaticAttributesEntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct ReportProxyActivity public readonly partial struct MetricsStaticAttributesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public MetricsStaticAttributesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.Mutable.cs index 7f1d423c8f7..84490db7ce0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.Mutable.cs @@ -587,6 +587,46 @@ public bool RemoveTracesStaticAttributes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMetricsUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMetrics(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableTracesUtf8, out IJsonDocument? _, out int _)) + { + SetDisableTraces(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.DisableProxyTrace.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReportHeadersValueUtf8, out IJsonDocument? _, out int _)) + { + SetReportHeadersValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.ReportHeaders.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.ReportHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.ReportHeaders.cs index 35db78739a3..032301729bc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.ReportHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.ReportHeaders.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public ReportHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs index 13650a0c23e..53b972b3541 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs index 4be8136e19a..fbfd33732a4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.TracesStaticAttributesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public TracesStaticAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.cs index 0a6274b4732..f48068591a4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.TracesStaticAttributesEntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct ReportProxyActivity public readonly partial struct TracesStaticAttributesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public TracesStaticAttributesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.cs index 54586465fe3..bf7051ed297 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.ReportProxyActivity.cs @@ -523,6 +523,12 @@ private void CheckValidInstance() public ReportProxyActivity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.cs index 2a7064cf895..cdfe6ba3221 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Layers.cs @@ -477,6 +477,12 @@ private void CheckValidInstance() public Layers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Mutable.cs index 3ae72824fbb..940863b43de 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.Mutable.cs @@ -752,6 +752,58 @@ public bool RemoveTraceSampleRateValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetricReportingPeriodUtf8, out IJsonDocument? _, out int _)) + { + SetMetricReportingPeriod(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.ReportingPeriod.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipPathsUtf8, out IJsonDocument? _, out int _)) + { + SetSkipPaths(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TraceSampleRateValueUtf8, out IJsonDocument? _, out int _)) + { + SetTraceSampleRateValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.TraceSampleRate.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExportersValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Exporters.Mutable __corvusExportersValue)) + { + __corvusExportersValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LayersValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Layers.Mutable __corvusLayersValue)) + { + __corvusLayersValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.ReportingPeriod.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.ReportingPeriod.cs index 183008e96e0..00b98252d86 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.ReportingPeriod.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.ReportingPeriod.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ReportingPeriod Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.TraceSampleRate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.TraceSampleRate.cs index f8d28d0cb9a..64985f4bbc6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.TraceSampleRate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.TraceSampleRate.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public TraceSampleRate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.cs index d678b614cb7..cf40aa68a81 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Opentelemetry.cs @@ -578,6 +578,12 @@ private void CheckValidInstance() public Opentelemetry Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.Mutable.cs index d6cc70d7f28..e178b311684 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.Mutable.cs @@ -379,6 +379,43 @@ public bool RemoveProxy() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportBackendActivity.Mutable __corvusBackend)) + { + __corvusBackend.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProxyUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportProxyActivity.Mutable __corvusProxy)) + { + __corvusProxy.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.DisableThisStage.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.DisableThisStage.cs index b1ce560fa58..009eeed394e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.DisableThisStage.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.DisableThisStage.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableThisStage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.Mutable.cs index 8068f60f6eb..36f0cd04f45 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.Mutable.cs @@ -241,6 +241,36 @@ public bool RemoveDisableStage() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableStageUtf8, out IJsonDocument? _, out int _)) + { + SetDisableStage(Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.DisableThisStage.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.cs index 0fa1487983d..11c45d15d10 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.cs @@ -421,6 +421,12 @@ private void CheckValidInstance() public MetricsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.Mutable.cs index 510fdab4d5a..86e702c37b0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.Mutable.cs @@ -363,6 +363,43 @@ public bool RemoveTraces() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetricsUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportBackendActivity.MetricsEntity.Mutable __corvusMetrics)) + { + __corvusMetrics.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TracesUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.Mutable __corvusTraces)) + { + __corvusTraces.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.DisableThisStage.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.DisableThisStage.cs index 7d89c1fcd42..789e7e74283 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.DisableThisStage.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.DisableThisStage.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableThisStage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.Mutable.cs index 2f1c894080e..f0df6c9a8a6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.Mutable.cs @@ -241,6 +241,36 @@ public bool RemoveDisableStage() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableStageUtf8, out IJsonDocument? _, out int _)) + { + SetDisableStage(Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.DisableThisStage.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.cs index 9b65e76c7d9..1cbb23a1caa 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.TracesEntity.cs @@ -421,6 +421,12 @@ private void CheckValidInstance() public TracesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.cs index 903d63c7293..e159ffcd875 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportBackendActivity.cs @@ -434,6 +434,12 @@ private void CheckValidInstance() public ReportBackendActivity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableMetrics.cs index 08b16efc8c4..d8b6d7702dc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableMetrics.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DisableMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableTraces.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableTraces.cs index 491442c0be5..d13635644a8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableTraces.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableTraces.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DisableTraces Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.Mutable.cs index c94b43b6ea8..b5389c2538a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.Mutable.cs @@ -309,6 +309,41 @@ public bool RemoveDisableTracesValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMetricsValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMetricsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableTracesValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableTracesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryBackend.ReportProxyActivity.DisableTraces.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.cs index 72c414f8e78..a19a0de3218 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.ReportProxyActivity.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public ReportProxyActivity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.cs index 91e357a8c24..c332fdb3671 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryBackend.cs @@ -450,6 +450,12 @@ private void CheckValidInstance() public OpentelemetryBackend Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.Mutable.cs index 28ca9c85501..64c14dc56a7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.Mutable.cs @@ -515,6 +515,31 @@ public bool RemoveTraceSampleRateValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.TraceSampleRate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.TraceSampleRate.cs index 2af06ff6887..d2879705dba 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.TraceSampleRate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.TraceSampleRate.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public TraceSampleRate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.cs index f248048361b..ae4cbeaa0a0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ExportersOverride.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ExportersOverride Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.Mutable.cs index 2ed95a81b8e..89617775072 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.Mutable.cs @@ -376,6 +376,43 @@ public bool RemoveProxy() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExportersOverrideValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryEndpoint.ExportersOverride.Mutable __corvusExportersOverrideValue)) + { + __corvusExportersOverrideValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProxyUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.Mutable __corvusProxy)) + { + __corvusProxy.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableMetrics.cs index 1e23cdabba8..d1f00dd3bf7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableMetrics.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DisableMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableTraces.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableTraces.cs index 2f6ef31b239..74920e07bce 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableTraces.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableTraces.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DisableTraces Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.Mutable.cs index 732d87f7f0b..0b935ce8d89 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.Mutable.cs @@ -309,6 +309,41 @@ public bool RemoveDisableTracesValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMetricsValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMetricsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableTracesValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableTracesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.DisableTraces.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.cs index cf7c96f7b07..5e228fc853a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.ReportProxyActivity.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public ReportProxyActivity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.cs index 946a15dbba5..edbd48ebc63 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetryEndpoint.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public OpentelemetryEndpoint Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.Mutable.cs index 7e8a71bf55c..f5c7ba7fcd3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.Mutable.cs @@ -260,6 +260,31 @@ public void SetOtlp(in Corvus.KrakendBenchmark.Current.KrakendSchema.O _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.Mutable.cs index 4d51662dea5..114bffcb1ef 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveProperty() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.cs index 9c4f46343ee..e42e109d619 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.cs @@ -375,6 +375,12 @@ private void CheckValidInstance() public Headers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Mutable.cs index 40af3d4b72f..15f7e40a27f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Mutable.cs @@ -323,6 +323,37 @@ public void SetName(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeadersValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.Headers.Mutable __corvusHeadersValue)) + { + __corvusHeadersValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.cs index e79e68e534e..d26cac76289 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.RequiredHeadersAndName.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public RequiredHeadersAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.cs index d078e0ed6ab..c4dbb489df5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.RequiredHeadersAndNameArray.cs @@ -31,11 +31,13 @@ public readonly partial struct OpentelemetrySecurity public readonly partial struct RequiredHeadersAndNameArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public RequiredHeadersAndNameArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.cs index f63544ce4c5..9532e70e7cc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OpentelemetrySecurity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public OpentelemetrySecurity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OutputEncoding.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OutputEncoding.cs index d8bfa7fd600..ebcf808e029 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OutputEncoding.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.OutputEncoding.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public OutputEncoding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Folder.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Folder.cs index 83012c87e12..d8d17747471 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Folder.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Folder.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public Folder Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Mutable.cs index ef9606a9377..9dd756a17f7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Mutable.cs @@ -324,6 +324,41 @@ public void SetPatternValue(scoped in Corvus.KrakendBenchmark.Current.KrakendSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FolderValueUtf8, out IJsonDocument? _, out int _)) + { + SetFolderValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Plugin.Folder.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PatternValueUtf8, out IJsonDocument? _, out int _)) + { + SetPatternValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Plugin.Pattern.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Pattern.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Pattern.cs index ec9762e4139..323fb124171 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Pattern.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.Pattern.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public Pattern Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.cs index f7df00199f0..0b62b45a0cc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Plugin.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public Plugin Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.Mutable.cs index c567e5a58f6..d7ef9d3f81e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.Mutable.cs @@ -282,6 +282,31 @@ public bool RemoveName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.cs index 1c27b85892f..74f0ad44f65 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginHttpClient.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public PluginHttpClient Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.Mutable.cs index 09c4a46ba89..bdc1eff3e77 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.Mutable.cs @@ -391,6 +391,31 @@ public bool RemoveSkip() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.cs index c81d7de5293..019fc42fa1c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.PluginStaticFilesystem.cs @@ -481,6 +481,12 @@ private void CheckValidInstance() public PluginStaticFilesystem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.AutoJoinPolicies.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.AutoJoinPolicies.cs index dbab362cf8c..8c09ea301fb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.AutoJoinPolicies.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.AutoJoinPolicies.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AutoJoinPolicies Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DebugEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DebugEntity.cs index 3152399d432..741f164246b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DebugEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DebugEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DebugEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DisableAdvancedMacros.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DisableAdvancedMacros.cs index 06eb7f51bf0..2b4df3875c3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DisableAdvancedMacros.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.DisableAdvancedMacros.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DisableAdvancedMacros Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.JsonStringArray.cs index 8cd7f2a2931..045bc5b962f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.JsonStringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct JwtPolicies public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.Mutable.cs index cf9f319e5f9..e956fa58d08 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.Mutable.cs @@ -262,6 +262,31 @@ public void SetPolicies(in Corvus.KrakendBenchmark.Current.KrakendSche _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.cs index cbdf008b4a4..f7145ec44d0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.JwtPolicies.cs @@ -430,6 +430,12 @@ private void CheckValidInstance() public JwtPolicies Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.Mutable.cs index 1be87742308..297804ece92 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.Mutable.cs @@ -740,6 +740,64 @@ public bool RemoveResp() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AutoJoinPoliciesValueUtf8, out IJsonDocument? _, out int _)) + { + SetAutoJoinPoliciesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.AutoJoinPolicies.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.DebugEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMacrosUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMacros(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.DisableAdvancedMacros.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JwtUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.JwtPolicies.Mutable __corvusJwt)) + { + __corvusJwt.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReqUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.RequestPolicies.Mutable __corvusReq)) + { + __corvusReq.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RespUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.ResponsePolicies.Mutable __corvusResp)) + { + __corvusResp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ContentType.cs index 238df97e993..2c9371ac4dc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ContentType.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public ContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ErrorBody.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ErrorBody.cs index 4c652de9715..59812b35960 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ErrorBody.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.ErrorBody.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public ErrorBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.HttpStatusCode.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.HttpStatusCode.cs index b2c78bf6184..23a5d01a465 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.HttpStatusCode.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.HttpStatusCode.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public HttpStatusCode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.Mutable.cs index 95f2fecd4cc..5e9966aa385 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.Mutable.cs @@ -426,6 +426,46 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BodyUtf8, out IJsonDocument? _, out int _)) + { + SetBody(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.RequestPolicies.ErrorEntity.ErrorBody.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentTypeValueUtf8, out IJsonDocument? _, out int _)) + { + SetContentTypeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.RequestPolicies.ErrorEntity.ContentType.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatusUtf8, out IJsonDocument? _, out int _)) + { + SetStatus(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.RequestPolicies.ErrorEntity.HttpStatusCode.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.cs index 81baeb24e7d..662a88f7265 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.ErrorEntity.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public ErrorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.JsonStringArray.cs index 97cae442389..f268b3d321b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.JsonStringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct RequestPolicies public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.Mutable.cs index 0ef1e4607ba..e4d857121f2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.Mutable.cs @@ -359,6 +359,37 @@ public void SetPolicies(in Corvus.KrakendBenchmark.Current.KrakendSche _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ErrorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.RequestPolicies.ErrorEntity.Mutable __corvusError)) + { + __corvusError.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.cs index 75f3c181051..263971e289b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequestPolicies.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public RequestPolicies Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.Mutable.cs index 815f482931d..afca459cd3b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.Mutable.cs @@ -300,6 +300,31 @@ public void SetJwt(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.cs index b34323c3db0..23b55873f9d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredJwt.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredJwt Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.Mutable.cs index 820ed27da1e..63d9c3c52fc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.Mutable.cs @@ -300,6 +300,31 @@ public void SetReq(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.cs index aa8da813d92..087dd1c6e42 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredReq.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredReq Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.Mutable.cs index 6fbe005b5d0..9ccd8045dcf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.Mutable.cs @@ -300,6 +300,31 @@ public void SetResp(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.cs index a980277bbd1..8fa99891c8a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.RequiredResp.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredResp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ContentType.cs index 65ca5d92d4c..613eafac6a6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ContentType.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public ContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ErrorBody.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ErrorBody.cs index 558fed849bd..a3c61484a37 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ErrorBody.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ErrorBody.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public ErrorBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.HttpStatusCode.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.HttpStatusCode.cs index 45b26bc4bdd..af0ae99a934 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.HttpStatusCode.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.HttpStatusCode.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public HttpStatusCode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.Mutable.cs index ad429bd4934..641b5942b03 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.Mutable.cs @@ -426,6 +426,46 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BodyUtf8, out IJsonDocument? _, out int _)) + { + SetBody(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ErrorBody.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentTypeValueUtf8, out IJsonDocument? _, out int _)) + { + SetContentTypeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.ResponsePolicies.ErrorEntity.ContentType.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatusUtf8, out IJsonDocument? _, out int _)) + { + SetStatus(Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.ResponsePolicies.ErrorEntity.HttpStatusCode.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.cs index cabde7003e5..9f0861a4d33 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.ErrorEntity.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public ErrorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.JsonStringArray.cs index 94d344de3ad..b49fd990a44 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.JsonStringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct ResponsePolicies public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.Mutable.cs index 17eefc46bc6..cbbd95cfdf1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.Mutable.cs @@ -359,6 +359,37 @@ public void SetPolicies(in Corvus.KrakendBenchmark.Current.KrakendSche _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ErrorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.ResponsePolicies.ErrorEntity.Mutable __corvusError)) + { + __corvusError.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.cs index 7ab4ee037d0..8a3350299ab 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.ResponsePolicies.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public ResponsePolicies Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.cs index 6502d4f6e14..24f18221506 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Policies.cs @@ -622,6 +622,12 @@ private void CheckValidInstance() public Policies Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Port.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Port.cs index 1da38a2739d..9d05bf78faa 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Port.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Port.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public Port Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.BackoffStrategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.BackoffStrategy.cs index 1afbb0469df..16ab2f5e7a4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.BackoffStrategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.BackoffStrategy.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public BackoffStrategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Delete.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Delete.cs index 38f0fd012e4..9a896e585f4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Delete.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Delete.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Delete Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Durable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Durable.cs index 029e736cda5..0f29a3a9c24 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Durable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Durable.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Durable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Exclusive.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Exclusive.cs index 57b6e84b006..f4c98c2707e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Exclusive.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Exclusive.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Exclusive Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ExpirationKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ExpirationKey.cs index e63aefe9198..79321eb5c10 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ExpirationKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ExpirationKey.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ExpirationKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Immediate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Immediate.cs index 6653e38ab51..07e6e70e685 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Immediate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Immediate.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Immediate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mandatory.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mandatory.cs index f0bb74c5dff..3af7a1d895f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mandatory.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mandatory.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Mandatory Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.MaxRetries.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.MaxRetries.cs index 1e4f3e52546..67f1790e3e8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.MaxRetries.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.MaxRetries.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaxRetries Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mutable.cs index 3811dd8f263..792aab8e6a4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.Mutable.cs @@ -1324,6 +1324,96 @@ public bool RemoveStaticRoutingKeyValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackoffStrategyValueUtf8, out IJsonDocument? _, out int _)) + { + SetBackoffStrategyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.BackoffStrategy.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeleteValueUtf8, out IJsonDocument? _, out int _)) + { + SetDeleteValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.Delete.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DurableValueUtf8, out IJsonDocument? _, out int _)) + { + SetDurableValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.Durable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExclusiveValueUtf8, out IJsonDocument? _, out int _)) + { + SetExclusiveValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.Exclusive.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExpKeyUtf8, out IJsonDocument? _, out int _)) + { + SetExpKey(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.ExpirationKey.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImmediateValueUtf8, out IJsonDocument? _, out int _)) + { + SetImmediateValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.Immediate.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MandatoryValueUtf8, out IJsonDocument? _, out int _)) + { + SetMandatoryValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.Mandatory.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxRetriesValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxRetriesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.MaxRetries.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MsgIdKeyUtf8, out IJsonDocument? _, out int _)) + { + SetMsgIdKey(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.ProducerExpirationKey.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PriorityKeyUtf8, out IJsonDocument? _, out int _)) + { + SetPriorityKey(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.ProducerExpirationKey1.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReplyToKeyUtf8, out IJsonDocument? _, out int _)) + { + SetReplyToKey(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.ProducerExpirationKey2.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoutingKeyValueUtf8, out IJsonDocument? _, out int _)) + { + SetRoutingKeyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.RoutingKey.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StaticRoutingKeyValueUtf8, out IJsonDocument? _, out int _)) + { + SetStaticRoutingKeyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Producer.StaticRoutingKey.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey.cs index d5fac288bde..8177cbcfe09 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ProducerExpirationKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey1.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey1.cs index 7b7b1bcaccb..b93114a08be 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey1.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey1.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ProducerExpirationKey1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey2.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey2.cs index f5025b19905..210d90e3dc2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey2.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.ProducerExpirationKey2.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ProducerExpirationKey2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.RoutingKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.RoutingKey.cs index 31b5dbf715e..db4156eb18d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.RoutingKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.RoutingKey.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public RoutingKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.StaticRoutingKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.StaticRoutingKey.cs index c04a524c76a..ca78ccdda6a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.StaticRoutingKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.StaticRoutingKey.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public StaticRoutingKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.cs index 008f5ec9eaf..d74c4e0b973 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Producer.cs @@ -834,6 +834,12 @@ private void CheckValidInstance() public Producer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.DecompressGzip.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.DecompressGzip.cs index 6e6771a9731..2cb85caaaeb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.DecompressGzip.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.DecompressGzip.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DecompressGzip Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.MaximumPayload.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.MaximumPayload.cs index 0df1438dd60..cd3a59b9a16 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.MaximumPayload.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.MaximumPayload.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaximumPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.Mutable.cs index 0b6273b34fd..709c450179f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.Mutable.cs @@ -489,6 +489,46 @@ public bool RemoveShadow() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DecompressGzipValueUtf8, out IJsonDocument? _, out int _)) + { + SetDecompressGzipValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Proxy.DecompressGzip.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxPayloadUtf8, out IJsonDocument? _, out int _)) + { + SetMaxPayload(Corvus.KrakendBenchmark.Current.KrakendSchema.Proxy.MaximumPayload.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShadowUtf8, out IJsonDocument? _, out int _)) + { + SetShadow(Corvus.KrakendBenchmark.Current.KrakendSchema.Proxy.TrafficShadowingOrMirroring.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.TrafficShadowingOrMirroring.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.TrafficShadowingOrMirroring.cs index 0181006d196..9aefe6d16cf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.TrafficShadowingOrMirroring.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.TrafficShadowingOrMirroring.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TrafficShadowingOrMirroring Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.cs index b8b42063dbf..a9a859f6d70 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Proxy.cs @@ -498,6 +498,12 @@ private void CheckValidInstance() public Proxy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.Mutable.cs index 28af5d5fecd..3d7b80fcd22 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.Mutable.cs @@ -226,6 +226,31 @@ public void SetTopicUrl(scoped in Corvus.KrakendBenchmark.Current.JsonString.Sou _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.cs index 01303fad7b5..f8de348f6fb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Publisher.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public Publisher Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Capacity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Capacity.cs index 6ecaec75689..cbc7c3b009c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Capacity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Capacity.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public Capacity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Mutable.cs index 010e279051c..a8900d455de 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.Mutable.cs @@ -358,6 +358,36 @@ public void SetMaxRate(scoped in Corvus.KrakendBenchmark.Current.JsonNumber.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CapacityValueUtf8, out IJsonDocument? _, out int _)) + { + SetCapacityValue(Corvus.KrakendBenchmark.Current.KrakendSchema.RatelimitProxy.Capacity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.cs index 3a8e0fc01ed..9b33bf51734 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RatelimitProxy.cs @@ -484,6 +484,12 @@ private void CheckValidInstance() public RatelimitProxy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Mutable.cs index 3ec0bcd4aa4..f5bc12bf2f8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Mutable.cs @@ -535,6 +535,31 @@ public bool RemoveTokenizerField() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Tokenizer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Tokenizer.cs index 849d5c28ada..91fd66676fe 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Tokenizer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.Tokenizer.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public Tokenizer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.cs index cf41dadf43f..edcfe879553 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.RedisRatelimit.cs @@ -568,6 +568,12 @@ private void CheckValidInstance() public RedisRatelimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.Mutable.cs index 806f75c87d5..af376de9566 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.Mutable.cs @@ -633,6 +633,48 @@ public bool RemoveResponseSchemaValidatorValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NameUtf8, out IJsonDocument? _, out int _)) + { + SetName(Corvus.KrakendBenchmark.Current.KrakendSchema.ReqRespModifier.PluginName.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IpFilterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.IpFilter.Mutable __corvusIpFilterValue)) + { + __corvusIpFilterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResponseSchemaValidatorValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ResponseSchemaValidator.Mutable __corvusResponseSchemaValidatorValue)) + { + __corvusResponseSchemaValidatorValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.PluginName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.PluginName.cs index fc94dc71454..940a87558ae 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.PluginName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.PluginName.cs @@ -44,11 +44,13 @@ public readonly partial struct ReqRespModifier public readonly partial struct PluginName #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public PluginName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.cs index fd798d26552..ad185dca161 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ReqRespModifier.cs @@ -436,6 +436,12 @@ private void CheckValidInstance() public ReqRespModifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.JsonStringArray.cs index 0e4a4dc9308..121aec9948f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct HeadersToAdd public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.cs index 5c044ed0e93..40cb3bb3a8e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToAdd.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public HeadersToAdd Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.JsonStringArray.cs index 3823438d5cd..f1ccfda8757 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.JsonStringArray.cs @@ -25,11 +25,13 @@ public readonly partial struct HeadersToReplace public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.cs index 40f9dbb8387..3ff616874b6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.HeadersToReplace.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public HeadersToReplace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.JsonStringArray.cs index 7e5ff7e11eb..95e646bd9ca 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct ResponseHeaders public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.Mutable.cs index 81be7e2f992..e336b4a8cff 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.Mutable.cs @@ -485,6 +485,31 @@ public bool RemoveReplace() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.cs index 3def01dab42..bddbb8e574e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseHeaders.cs @@ -475,6 +475,12 @@ private void CheckValidInstance() public ResponseHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorBody.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorBody.cs index 49591564281..984104db7a4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorBody.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorBody.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public ErrorBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorCode.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorCode.cs index c0f1fd4af2b..282eb66fba6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorCode.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorCode.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public ErrorCode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.Mutable.cs index 784223411ec..686a9ea772b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.Mutable.cs @@ -303,6 +303,41 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BodyUtf8, out IJsonDocument? _, out int _)) + { + SetBody(Corvus.KrakendBenchmark.Current.KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorBody.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatusUtf8, out IJsonDocument? _, out int _)) + { + SetStatus(Corvus.KrakendBenchmark.Current.KrakendSchema.ResponseSchemaValidator.ErrorDefinition.ErrorCode.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.cs index 24a5a1e9c91..d513c645a16 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.ErrorDefinition.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public ErrorDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.Mutable.cs index b4ac87b577f..6c002b88153 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.Mutable.cs @@ -366,6 +366,37 @@ public void SetSchema(in Corvus.KrakendBenchmark.Current.JsonObject.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ErrorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ResponseSchemaValidator.ErrorDefinition.Mutable __corvusError)) + { + __corvusError.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.cs index 6128601c710..b9deecd3eda 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ResponseSchemaValidator.cs @@ -453,6 +453,12 @@ private void CheckValidInstance() public ResponseSchemaValidator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.HashFunctionName.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.HashFunctionName.cs index a6e5fc03f33..cb7f86d5489 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.HashFunctionName.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.HashFunctionName.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public HashFunctionName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.MaxWorkers.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.MaxWorkers.cs index b4c10779044..849b3e4097c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.MaxWorkers.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.MaxWorkers.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaxWorkers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.Mutable.cs index 6cbaf02588b..4d7c416487a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.Mutable.cs @@ -908,6 +908,41 @@ public void SetTokenKeys(in Corvus.KrakendBenchmark.Current.JsonArray. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RevokeServerMaxRetriesValueUtf8, out IJsonDocument? _, out int _)) + { + SetRevokeServerMaxRetriesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Revoker.RevokeServerMaxRetries.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RevokeServerMaxWorkersUtf8, out IJsonDocument? _, out int _)) + { + SetRevokeServerMaxWorkers(Corvus.KrakendBenchmark.Current.KrakendSchema.Revoker.MaxWorkers.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.RevokeServerMaxRetries.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.RevokeServerMaxRetries.cs index b8232764c94..438be62b8bf 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.RevokeServerMaxRetries.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.RevokeServerMaxRetries.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public RevokeServerMaxRetries Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.cs index 9dddace9203..aa294241899 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Revoker.cs @@ -693,6 +693,12 @@ private void CheckValidInstance() public Revoker Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Capacity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Capacity.cs index 9e249f22530..a7e29be34dc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Capacity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Capacity.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public Capacity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.CleanupThreads.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.CleanupThreads.cs index d56067322ca..fd3bab62e91 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.CleanupThreads.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.CleanupThreads.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public CleanupThreads Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.ClientCapacity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.ClientCapacity.cs index 70004e7cbaa..309c4042075 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.ClientCapacity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.ClientCapacity.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ClientCapacity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Mutable.cs index 73f2bba57c4..343ea0fafd8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Mutable.cs @@ -954,6 +954,51 @@ public bool RemoveStrategyValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CapacityValueUtf8, out IJsonDocument? _, out int _)) + { + SetCapacityValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Router.Capacity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CleanupThreadsValueUtf8, out IJsonDocument? _, out int _)) + { + SetCleanupThreadsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Router.CleanupThreads.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ClientCapacityValueUtf8, out IJsonDocument? _, out int _)) + { + SetClientCapacityValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Router.ClientCapacity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NumShardsValueUtf8, out IJsonDocument? _, out int _)) + { + SetNumShardsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Router.NumShards.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.NumShards.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.NumShards.cs index 33890eb6ff5..b56165dc500 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.NumShards.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.NumShards.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public NumShards Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.Mutable.cs index a918615b50b..b0f2d907597 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.Mutable.cs @@ -300,6 +300,31 @@ public void SetClientMaxRate(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.cs index f9fd8faaed7..172a9b69e36 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredClientMaxRate.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredClientMaxRate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.Mutable.cs index f8c655ffd9b..af6abeae2b8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.Mutable.cs @@ -300,6 +300,31 @@ public void SetMaxRate(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.cs index 2516e3dcded..575741c22ab 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.RequiredMaxRate.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredMaxRate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Strategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Strategy.cs index 4b0de597c9f..dd4c1c75100 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Strategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.Strategy.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public Strategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.cs index 77df9e4e082..75badd5e993 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Router.cs @@ -649,6 +649,12 @@ private void CheckValidInstance() public Router Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.Mutable.cs index d56902df1b9..0bc15859dc5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.Mutable.cs @@ -378,6 +378,37 @@ public bool RemoveServices() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OpentelemetryUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.Mutable __corvusOpentelemetry)) + { + __corvusOpentelemetry.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableMetrics.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableMetrics.cs index 795f589bd9a..2d052fa9660 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableMetrics.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableMetrics.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableMetrics Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableTrace.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableTrace.cs index b3123b122c1..51f70c5a54b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableTrace.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableTrace.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public DisableTrace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.Mutable.cs index 1ea44d2678a..3fe78d549ef 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.Mutable.cs @@ -311,6 +311,41 @@ public bool RemoveDisableTraces() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableMetricsValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableMetricsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableMetrics.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableTracesUtf8, out IJsonDocument? _, out int _)) + { + SetDisableTraces(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.DisableTrace.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.cs index a5a57fa6dbb..fcf0849545c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.OpenTelemetrySettings.cs @@ -451,6 +451,12 @@ private void CheckValidInstance() public OpenTelemetrySettings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.BackendArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.BackendArray.cs index b30a49ebda7..8db5776f75e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.BackendArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.BackendArray.cs @@ -38,11 +38,13 @@ public readonly partial struct MethodsEntity public readonly partial struct BackendArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -92,6 +94,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -305,6 +322,12 @@ private void CheckValidInstance() public BackendArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.Mutable.cs index 7ffafd80bc6..41ff701fa1c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.Mutable.cs @@ -288,6 +288,37 @@ public bool RemoveAuthValidator() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthValidatorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.Mutable __corvusAuthValidator)) + { + __corvusAuthValidator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.cs index 287dec0d8c0..3227f0f9fa9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.cs @@ -437,6 +437,12 @@ private void CheckValidInstance() public ExtraConfiguration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.JsonStringArray.cs index 9163108feee..d48ad7ae16c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.JsonStringArray.cs @@ -62,11 +62,13 @@ public readonly partial struct MethodsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -117,6 +119,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -330,6 +347,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.Mutable.cs index e0690d8b745..5debbb4a2fe 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.Mutable.cs @@ -667,6 +667,42 @@ public bool RemovePayloadParams() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputHeadersUtf8, out IJsonDocument? _, out int _)) + { + SetInputHeaders(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.JsonStringArray.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtraConfigUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.ExtraConfiguration.Mutable __corvusExtraConfig)) + { + __corvusExtraConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.cs index 2aa2bae424a..73474f2f297 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.MethodsEntity.cs @@ -523,6 +523,12 @@ private void CheckValidInstance() public MethodsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.cs index 77bf30555c9..b0ae807ab34 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.MethodsEntityArray.cs @@ -37,11 +37,13 @@ public readonly partial struct ServicesEntity public readonly partial struct MethodsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public MethodsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.Mutable.cs index 5d1afadf9a4..c49d53fa2cb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.Mutable.cs @@ -349,6 +349,31 @@ public bool RemoveName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.cs index 79059cfe5bf..8ed169d7c92 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.ServicesEntity.cs @@ -448,6 +448,12 @@ private void CheckValidInstance() public ServicesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.cs index b8326ab570b..1685e4fc231 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.ServicesEntityArray.cs @@ -33,11 +33,13 @@ public readonly partial struct GrpcServer public readonly partial struct ServicesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public ServicesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.cs index 08cc881bc30..74bf1771930 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.GrpcServer.cs @@ -449,6 +449,12 @@ private void CheckValidInstance() public GrpcServer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.JsonStringArray.cs index 56395c53772..2c9a57785d6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.JsonStringArray.cs @@ -49,11 +49,13 @@ public readonly partial struct SchemaGrpc public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -103,6 +105,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -316,6 +333,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.Mutable.cs index bf9eb41e936..8670fc60e87 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.Mutable.cs @@ -366,6 +366,37 @@ public bool RemoveServer() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaGrpc.GrpcServer.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.cs index 0dad2fb42db..de0c3ad0e88 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaGrpc.cs @@ -450,6 +450,12 @@ private void CheckValidInstance() public SchemaGrpc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.Mutable.cs index 86ebc7f7c13..e24236c0ae5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.Mutable.cs @@ -375,6 +375,31 @@ public bool RemoveV405() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.cs index a57facb8ef1..7f4d9dd9e1e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.CustomErrorBody.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public CustomErrorBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DecompressGzip.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DecompressGzip.cs index edfeb98e3f3..b0999cf96bd 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DecompressGzip.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DecompressGzip.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public DecompressGzip Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableAccessLog.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableAccessLog.cs index ecfc0475151..d8d244f9254 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableAccessLog.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableAccessLog.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableAccessLog Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableGzipCompression.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableGzipCompression.cs index 99a7188bd45..bba7a38664f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableGzipCompression.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableGzipCompression.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableGzipCompression Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableHealth.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableHealth.cs index 0ce65bb5abe..1accf2e4917 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableHealth.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.DisableHealth.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableHealth Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.EnableH2c.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.EnableH2c.cs index 189df8e9317..b282341f354 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.EnableH2c.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.EnableH2c.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EnableH2c Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ForwardedByClientIp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ForwardedByClientIp.cs index 3b428312f4c..63b6a2340f7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ForwardedByClientIp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ForwardedByClientIp.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ForwardedByClientIp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HealthEndpointPath.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HealthEndpointPath.cs index a7f749a14d0..6acf9b10bce 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HealthEndpointPath.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HealthEndpointPath.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public HealthEndpointPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HideVersionHeader.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HideVersionHeader.cs index 85459899e0a..598976bad69 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HideVersionHeader.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.HideVersionHeader.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public HideVersionHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.JsonStringArray.cs index 390b867983a..7e64167265d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct SchemaRouter public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.MaximumPayload.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.MaximumPayload.cs index 690efcfb1bc..2f79e2f6bfb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.MaximumPayload.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.MaximumPayload.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaximumPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.Mutable.cs index 5672e3df643..20f773487d3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.Mutable.cs @@ -1920,6 +1920,92 @@ public bool RemoveUseH2c() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DecompressGzipValueUtf8, out IJsonDocument? _, out int _)) + { + SetDecompressGzipValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.DecompressGzip.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableAccessLogValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableAccessLogValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.DisableAccessLog.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableGzipUtf8, out IJsonDocument? _, out int _)) + { + SetDisableGzip(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.DisableGzipCompression.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableHealthValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableHealthValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.DisableHealth.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ForwardedByClientIpValueUtf8, out IJsonDocument? _, out int _)) + { + SetForwardedByClientIpValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.ForwardedByClientIp.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HealthPathUtf8, out IJsonDocument? _, out int _)) + { + SetHealthPath(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.HealthEndpointPath.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HideVersionHeaderValueUtf8, out IJsonDocument? _, out int _)) + { + SetHideVersionHeaderValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.HideVersionHeader.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxPayloadUtf8, out IJsonDocument? _, out int _)) + { + SetMaxPayload(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.MaximumPayload.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RemoveExtraSlashValueUtf8, out IJsonDocument? _, out int _)) + { + SetRemoveExtraSlashValue(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.RemoveExtraSlash.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReturnErrorMsgUtf8, out IJsonDocument? _, out int _)) + { + SetReturnErrorMsg(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.ReturningTheGatewayErrorMessage.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseH2cUtf8, out IJsonDocument? _, out int _)) + { + SetUseH2c(Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.EnableH2c.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ErrorBodyUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.CustomErrorBody.Mutable __corvusErrorBody)) + { + __corvusErrorBody.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.RemoveExtraSlash.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.RemoveExtraSlash.cs index 0711c34c5eb..8d48724f15d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.RemoveExtraSlash.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.RemoveExtraSlash.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public RemoveExtraSlash Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ReturningTheGatewayErrorMessage.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ReturningTheGatewayErrorMessage.cs index 79233dde2f3..5e083ec5e5e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ReturningTheGatewayErrorMessage.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.ReturningTheGatewayErrorMessage.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ReturningTheGatewayErrorMessage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.cs index c696c740a51..1124f98779b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SchemaRouter.cs @@ -1019,6 +1019,12 @@ private void CheckValidInstance() public SchemaRouter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SequentialStart.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SequentialStart.cs index 01a5c431555..c53f77ed3f0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SequentialStart.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.SequentialStart.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public SequentialStart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.Mutable.cs index 9134ded4f37..0ba4562bf32 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.Mutable.cs @@ -457,6 +457,36 @@ public bool RemoveSkip() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DirectoryListingUtf8, out IJsonDocument? _, out int _)) + { + SetDirectoryListing(Corvus.KrakendBenchmark.Current.KrakendSchema.ServerStaticFilesystem.WhetherToAllowDirectoryListingsOrNot.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs index 55b6a5f4b76..b4c04b87e7f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhetherToAllowDirectoryListingsOrNot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.cs index 627bf5d71dd..87680b77fb0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerStaticFilesystem.cs @@ -502,6 +502,12 @@ private void CheckValidInstance() public ServerStaticFilesystem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.JsonStringArray.cs index 6b02f92874f..c12cbb7179d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct ServerVirtualhost public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.Mutable.cs index e3f79af65eb..c140f9dc487 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.Mutable.cs @@ -415,6 +415,37 @@ public bool RemoveHosts() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AliasedHostsUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.Mutable __corvusAliasedHosts)) + { + __corvusAliasedHosts.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.Mutable.cs index c73d7b2d4c5..fe30f830e00 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.Mutable.cs @@ -300,6 +300,31 @@ public void SetAliasedHosts(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.cs index 23fc260ad82..0fd8c45f161 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredAliasedHosts.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredAliasedHosts Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.Mutable.cs index 1e5ff5a9bd9..14b788a4e29 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.Mutable.cs @@ -300,6 +300,31 @@ public void SetHosts(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.cs index 5fc3f800aab..8bc9dd9a566 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.RequiredHosts.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredHosts Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.Mutable.cs index da9f7303e4b..9d8a0156532 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveAZ09() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.cs index de4cb95caa1..efbc64badb5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.VirtualhostsWithAlias.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public VirtualhostsWithAlias Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.cs index 4c24ce068ff..10e7b224d52 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServerVirtualhost.cs @@ -504,6 +504,12 @@ private void CheckValidInstance() public ServerVirtualhost Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowCredentials.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowCredentials.cs index 8d3d58be7f5..67477cc4bda 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowCredentials.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowCredentials.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public AllowCredentials Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowedHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowedHeaders.cs index b15855867ab..26fd357e21a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowedHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowedHeaders.cs @@ -35,11 +35,13 @@ public readonly partial struct CrossOriginResourceSharing public readonly partial struct AllowedHeaders #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public AllowedHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ExposeHeaders.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ExposeHeaders.cs index 5b84f4cac49..633d49c4739 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ExposeHeaders.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ExposeHeaders.cs @@ -41,11 +41,13 @@ public readonly partial struct CrossOriginResourceSharing public readonly partial struct ExposeHeaders #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public ExposeHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.JsonStringArray.cs index e4931a71596..1d21a63ad38 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.JsonStringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CrossOriginResourceSharing public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.Mutable.cs index 3b22b30be93..955fc0164e0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.Mutable.cs @@ -840,6 +840,51 @@ public bool RemoveMaxAge() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowCredentialsValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowCredentialsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowCredentials.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowHeadersUtf8, out IJsonDocument? _, out int _)) + { + SetAllowHeaders(Corvus.KrakendBenchmark.Current.KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.AllowedHeaders.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ShowDebug.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExposeHeadersValueUtf8, out IJsonDocument? _, out int _)) + { + SetExposeHeadersValue(Corvus.KrakendBenchmark.Current.KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ExposeHeaders.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.ObjectInArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.ObjectInArray.cs index a84498d9a57..85b78cb2f60 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.ObjectInArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.ObjectInArray.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public ObjectInArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.cs index 888cf026d60..1b3dfcfcbbe 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ObjectInArrayArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CrossOriginResourceSharing public readonly partial struct ObjectInArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public ObjectInArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ShowDebug.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ShowDebug.cs index 1e31ca910a1..4c75fab2c61 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ShowDebug.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.ShowDebug.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ShowDebug Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.cs index dfe7b631df0..c5158769609 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.cs @@ -535,6 +535,12 @@ private void CheckValidInstance() public CrossOriginResourceSharing Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.Mutable.cs index 66fd7dbe406..58789272e51 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.Mutable.cs @@ -3096,6 +3096,204 @@ public bool RemoveTelemetryOpentelemetrySecurity() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityCorsUtf8, out IJsonDocument? _, out int _)) + { + SetSecurityCors(Corvus.KrakendBenchmark.Current.KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthApiKeysUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ApiKeys.Mutable __corvusAuthApiKeys)) + { + __corvusAuthApiKeys.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthBasicUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Basic.Mutable __corvusAuthBasic)) + { + __corvusAuthBasic.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthRevokerUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Revoker.Mutable __corvusAuthRevoker)) + { + __corvusAuthRevoker.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthValidatorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Jose.Mutable __corvusAuthValidator)) + { + __corvusAuthValidator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentationOpenapiUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Openapi.Mutable __corvusDocumentationOpenapi)) + { + __corvusDocumentationOpenapi.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GithubComLetgoappKrakendInfluxUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Influx.Mutable __corvusGithubComLetgoappKrakendInflux)) + { + __corvusGithubComLetgoappKrakendInflux.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GrpcUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaGrpc.Mutable __corvusGrpc)) + { + __corvusGrpc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierLuaEndpointUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.Mutable __corvusModifierLuaEndpoint)) + { + __corvusModifierLuaEndpoint.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierResponseHeadersUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ResponseHeaders.Mutable __corvusModifierResponseHeaders)) + { + __corvusModifierResponseHeaders.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginHttpServerUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.HttpServer.Mutable __corvusPluginHttpServer)) + { + __corvusPluginHttpServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QosRatelimitServiceUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Router.Mutable __corvusQosRatelimitService)) + { + __corvusQosRatelimitService.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QosRatelimitTieredUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Tiered.Mutable __corvusQosRatelimitTiered)) + { + __corvusQosRatelimitTiered.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RouterValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.SchemaRouter.Mutable __corvusRouterValue)) + { + __corvusRouterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityBotDetectorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BotDetector.Mutable __corvusSecurityBotDetector)) + { + __corvusSecurityBotDetector.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityCorsUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ServiceExtraConfig.CrossOriginResourceSharing.Mutable __corvusSecurityCors)) + { + __corvusSecurityCors.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityHttpUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Http.Mutable __corvusSecurityHttp)) + { + __corvusSecurityHttp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerStaticFilesystemValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ServerStaticFilesystem.Mutable __corvusServerStaticFilesystemValue)) + { + __corvusServerStaticFilesystemValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerVirtualhostValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ServerVirtualhost.Mutable __corvusServerVirtualhostValue)) + { + __corvusServerVirtualhostValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryGelfUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Gelf.Mutable __corvusTelemetryGelf)) + { + __corvusTelemetryGelf.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryInfluxUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Influx.Mutable __corvusTelemetryInflux)) + { + __corvusTelemetryInflux.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryLoggingUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Logging.Mutable __corvusTelemetryLogging)) + { + __corvusTelemetryLogging.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryLogstashUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Logstash.Mutable __corvusTelemetryLogstash)) + { + __corvusTelemetryLogstash.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryMetricsUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Metrics.Mutable __corvusTelemetryMetrics)) + { + __corvusTelemetryMetrics.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryMoesifUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Moesif.Mutable __corvusTelemetryMoesif)) + { + __corvusTelemetryMoesif.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryNewrelicUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Newrelic.Mutable __corvusTelemetryNewrelic)) + { + __corvusTelemetryNewrelic.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryOpencensusUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opencensus.Mutable __corvusTelemetryOpencensus)) + { + __corvusTelemetryOpencensus.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryOpentelemetryUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Opentelemetry.Mutable __corvusTelemetryOpentelemetry)) + { + __corvusTelemetryOpentelemetry.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TelemetryOpentelemetrySecurityUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.OpentelemetrySecurity.Mutable __corvusTelemetryOpentelemetrySecurity)) + { + __corvusTelemetryOpentelemetrySecurity.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.cs index c03aa60e3e9..c2f331df3b8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.ServiceExtraConfig.cs @@ -1053,6 +1053,12 @@ private void CheckValidInstance() public ServiceExtraConfig Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Algorithm.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Algorithm.cs index 51e56f4008b..41dddf688bb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Algorithm.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Algorithm.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public Algorithm Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.DisableJwkSecurity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.DisableJwkSecurity.cs index 3a04b533685..75fa75266d4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.DisableJwkSecurity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.DisableJwkSecurity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableJwkSecurity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.FullFormat.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.FullFormat.cs index a31418e09ff..e7602551693 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.FullFormat.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.FullFormat.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public FullFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Mutable.cs index eb160ebb465..258b5a997c2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.Mutable.cs @@ -1186,6 +1186,46 @@ public bool RemoveSecretUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CipherSuitesUtf8, out IJsonDocument? _, out int _)) + { + SetCipherSuites(Corvus.KrakendBenchmark.Current.KrakendSchema.Signer.ObjectInArrayArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableJwkSecurityValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableJwkSecurityValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Signer.DisableJwkSecurity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FullUtf8, out IJsonDocument? _, out int _)) + { + SetFull(Corvus.KrakendBenchmark.Current.KrakendSchema.Signer.FullFormat.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.ObjectInArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.ObjectInArray.cs index 28ee95bca90..803c39552ed 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.ObjectInArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.ObjectInArray.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public ObjectInArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.cs index 60229a59640..51f9bae4467 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.ObjectInArrayArray.cs @@ -36,11 +36,13 @@ public readonly partial struct Signer public readonly partial struct ObjectInArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -119,6 +121,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -332,6 +349,12 @@ private void CheckValidInstance() public ObjectInArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.Mutable.cs index 0aa6ca5693f..a3acf980a17 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.Mutable.cs @@ -472,6 +472,31 @@ public void SetJwkLocalPath(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.cs index 3c2b083d758..e40a3a53b4f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndDisableJwkSecurityAndJwkLocalPath.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public RequiredAlgAndDisableJwkSecurityAndJwkLocalPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.Mutable.cs index bc1cb3f7688..875cc0b1a70 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.Mutable.cs @@ -386,6 +386,31 @@ public void SetJwkUrl(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.cs index 2cd417691f2..52ac4dc7512 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.RequiredAlgAndJwkUrl.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredAlgAndJwkUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.SecretSUrl.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.SecretSUrl.cs index 869af229e80..c71e6c0c19f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.SecretSUrl.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.SecretSUrl.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public SecretSUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.cs index 41017cd0aca..40ce3013c0d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Signer.cs @@ -788,6 +788,12 @@ private void CheckValidInstance() public Signer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.ContentType.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.ContentType.cs index 6cf3ef29bbd..c689d89dc01 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.ContentType.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.ContentType.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public ContentType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.EnableDebug.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.EnableDebug.cs index 28b2b96add0..bc6e28a4789 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.EnableDebug.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.EnableDebug.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EnableDebug Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.Mutable.cs index ebe6083a318..60bbed3923b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.Mutable.cs @@ -552,6 +552,41 @@ public bool RemoveTemplate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentTypeValueUtf8, out IJsonDocument? _, out int _)) + { + SetContentTypeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Soap.ContentType.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DebugValueUtf8, out IJsonDocument? _, out int _)) + { + SetDebugValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Soap.EnableDebug.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.Mutable.cs index a9555f8cf74..a293b099a46 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.Mutable.cs @@ -300,6 +300,31 @@ public void SetPath(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.cs index 101b1c4aef9..d820a6cd2c5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredPath.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.Mutable.cs index 737729d4b22..d5bad44bd70 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.Mutable.cs @@ -300,6 +300,31 @@ public void SetTemplate(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.cs index 9b65120a0c6..a3662314e82 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.RequiredTemplate.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.cs index c26985b35cc..7bee494bfc1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Soap.cs @@ -623,6 +623,12 @@ private void CheckValidInstance() public Soap Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.Mutable.cs index ed8919d45cc..01d53767e75 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.Mutable.cs @@ -292,6 +292,36 @@ public void SetPath(scoped in Corvus.KrakendBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DirectoryListingUtf8, out IJsonDocument? _, out int _)) + { + SetDirectoryListing(Corvus.KrakendBenchmark.Current.KrakendSchema.StaticFilesystem.WhetherToAllowDirectoryListingsOrNot.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs index 2225ff9a440..3609ac7c03b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.WhetherToAllowDirectoryListingsOrNot.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhetherToAllowDirectoryListingsOrNot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.cs index 7832c50e694..33eafb85ceb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.StaticFilesystem.cs @@ -449,6 +449,12 @@ private void CheckValidInstance() public StaticFilesystem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.Mutable.cs index d14cb9bfdb2..c695d78ecfc 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.Mutable.cs @@ -226,6 +226,31 @@ public void SetSubscriptionUrl(scoped in Corvus.KrakendBenchmark.Current.JsonStr _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.cs index 3d368f04402..d28f62b4131 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Subscriber.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public Subscriber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.Mutable.cs index f9f5b67f0d5..064bfce09c5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.Mutable.cs @@ -364,6 +364,31 @@ public void SetTiers(in Corvus.KrakendBenchmark.Current.KrakendSchema. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.Mutable.cs index b47671d67b5..89a32017a2e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.Mutable.cs @@ -462,6 +462,47 @@ public bool RemoveTierValueAsValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TierValueValueUtf8, out IJsonDocument? _, out int _)) + { + SetTierValueValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValue.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TierValueAsValueUtf8, out IJsonDocument? _, out int _)) + { + SetTierValueAsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValueAs.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RatelimitUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Router.Mutable __corvusRatelimit)) + { + __corvusRatelimit.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValue.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValue.cs index 7f6d6e2f63b..a6da43c9e64 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValue.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValue.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public TierValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValueAs.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValueAs.cs index 38203657000..32692f4c8e8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValueAs.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.TierValueAs.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TierValueAs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.cs index 894c532b7e6..a52a6420b98 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.TiersEntity.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public TiersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.cs index 82f3155e278..f7ba2f2d08f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.TiersEntityArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Tiered public readonly partial struct TiersEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public TiersEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.cs index af93a15a8d9..3011408e153 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tiered.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public Tiered Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CaCertificatesForMtls.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CaCertificatesForMtls.cs index 5387c3df692..21ec93047c6 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CaCertificatesForMtls.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CaCertificatesForMtls.cs @@ -39,11 +39,13 @@ public readonly partial struct Tls public readonly partial struct CaCertificatesForMtls #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public CaCertificatesForMtls Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CipherSuites.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CipherSuites.cs index f5f5b4a0b9b..9e161bc4037 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CipherSuites.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CipherSuites.cs @@ -39,11 +39,13 @@ public readonly partial struct Tls public readonly partial struct CipherSuites #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -89,6 +91,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -302,6 +319,12 @@ private void CheckValidInstance() public CipherSuites Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs index 51a3ecf1f42..257a00abf01 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.CurvePreferencesEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public CurvePreferencesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.cs index cc4147aacb3..7d416f566a0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.CurvePreferencesEntityArray.cs @@ -39,11 +39,13 @@ public readonly partial struct Tls public readonly partial struct CurvePreferencesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -122,6 +124,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -335,6 +352,12 @@ private void CheckValidInstance() public CurvePreferencesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableSystemSCa.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableSystemSCa.cs index 012852b0c3e..c456a319c4d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableSystemSCa.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableSystemSCa.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableSystemSCa Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableTls.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableTls.cs index 3b097909f79..febfa35698e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableTls.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.DisableTls.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableTls Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.EnableMutualAuthentication.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.EnableMutualAuthentication.cs index d75ffeec75d..b00339524e2 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.EnableMutualAuthentication.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.EnableMutualAuthentication.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public EnableMutualAuthentication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.Mutable.cs index 0aae7d1e013..498e0941263 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.Mutable.cs @@ -356,6 +356,41 @@ public bool RemovePublicKeyValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PrivateKeyValueUtf8, out IJsonDocument? _, out int _)) + { + SetPrivateKeyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.KeysEntityArray.KeysEntity.PrivateKey.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PublicKeyValueUtf8, out IJsonDocument? _, out int _)) + { + SetPublicKeyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.KeysEntityArray.KeysEntity.PublicKey.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PrivateKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PrivateKey.cs index 1bf9d96b226..54619b6bd79 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PrivateKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PrivateKey.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public PrivateKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PublicKey.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PublicKey.cs index eb8cfadbf12..0371895516a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PublicKey.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.PublicKey.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public PublicKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.cs index c664484399a..45747e608f8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.KeysEntity.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public KeysEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.cs index 928056d6786..4f7225a4182 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.KeysEntityArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Tls public readonly partial struct KeysEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public KeysEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MaximumTlsVersion.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MaximumTlsVersion.cs index cc8037b72c2..92fe15bcf5b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MaximumTlsVersion.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MaximumTlsVersion.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public MaximumTlsVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MinimumTlsVersion.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MinimumTlsVersion.cs index 7f71cf58540..a90eb3ce15c 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MinimumTlsVersion.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.MinimumTlsVersion.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public MinimumTlsVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.Mutable.cs index 3d0bb0eae18..481c846c0d1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.Mutable.cs @@ -1132,6 +1132,71 @@ public bool RemovePublicKey() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CaCertsUtf8, out IJsonDocument? _, out int _)) + { + SetCaCerts(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.CaCertificatesForMtls.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CipherSuitesValueUtf8, out IJsonDocument? _, out int _)) + { + SetCipherSuitesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.CipherSuites.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CurvePreferencesUtf8, out IJsonDocument? _, out int _)) + { + SetCurvePreferences(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.CurvePreferencesEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableSystemCaPoolUtf8, out IJsonDocument? _, out int _)) + { + SetDisableSystemCaPool(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.DisableSystemSCa.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisabledUtf8, out IJsonDocument? _, out int _)) + { + SetDisabled(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.DisableTls.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableMtlsUtf8, out IJsonDocument? _, out int _)) + { + SetEnableMtls(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.EnableMutualAuthentication.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxVersionUtf8, out IJsonDocument? _, out int _)) + { + SetMaxVersion(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.MaximumTlsVersion.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinVersionUtf8, out IJsonDocument? _, out int _)) + { + SetMinVersion(Corvus.KrakendBenchmark.Current.KrakendSchema.Tls.MinimumTlsVersion.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.Mutable.cs index 06b0d5d3d29..0466d3e4d65 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.Mutable.cs @@ -300,6 +300,31 @@ public void SetKeys(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.cs index b484e9f94d0..eba7e6abf34 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.RequiredKeys.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredKeys Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.cs index 57affafb3d6..4aa07d1fb0b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Tls.cs @@ -735,6 +735,12 @@ private void CheckValidInstance() public Tls Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.JsonArrayArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.JsonArrayArray.cs index 537782c0582..296563abd18 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.JsonArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.JsonArrayArray.cs @@ -31,11 +31,13 @@ public readonly partial struct UrlRewrite public readonly partial struct JsonArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.Mutable.cs index 97cc58c4a89..509dbefa1d4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.Mutable.cs @@ -415,6 +415,31 @@ public bool RemoveRegexp() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.Mutable.cs index 5ff94a4e81a..5e2f55936c9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.Mutable.cs @@ -300,6 +300,31 @@ public void SetLiteral(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.cs index 8cf61516dff..e5215460f08 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredLiteral.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredLiteral Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.Mutable.cs index 9e8eb89389f..5ebfe67dd20 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.Mutable.cs @@ -300,6 +300,31 @@ public void SetRegexp(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.cs index 8ff4237831c..45653c18cff 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.RequiredRegexp.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRegexp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.cs index 51801c52cef..a975132244e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.UrlRewrite.cs @@ -504,6 +504,12 @@ private void CheckValidInstance() public UrlRewrite Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Algorithm.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Algorithm.cs index 3cc1a19c384..305128825c9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Algorithm.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Algorithm.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Algorithm Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.AuthorizationHeader.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.AuthorizationHeader.cs index aef292983bd..873c23f37b8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.AuthorizationHeader.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.AuthorizationHeader.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public AuthorizationHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Cache.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Cache.cs index 6107a0efeef..6c0d7012fcb 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Cache.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Cache.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public Cache Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.CacheDuration.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.CacheDuration.cs index b102a7bc92b..c168c4ff6ae 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.CacheDuration.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.CacheDuration.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public CacheDuration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DebugEntity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DebugEntity.cs index a08c2744263..88b64688406 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DebugEntity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DebugEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DebugEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DisableJwkSecurity.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DisableJwkSecurity.cs index bed13994b01..3eca4112d87 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DisableJwkSecurity.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.DisableJwkSecurity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableJwkSecurity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.JsonStringArray.cs index 20a4866f796..3ba963a191e 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Validator public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.KeyIdentifyStrategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.KeyIdentifyStrategy.cs index 06aa704c799..7b077c653b9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.KeyIdentifyStrategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.KeyIdentifyStrategy.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public KeyIdentifyStrategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Mutable.cs index 4a01a5723da..5bfb7343d06 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.Mutable.cs @@ -2245,6 +2245,71 @@ public bool RemoveSecretUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AlgUtf8, out IJsonDocument? _, out int _)) + { + SetAlg(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.Algorithm.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthHeaderNameUtf8, out IJsonDocument? _, out int _)) + { + SetAuthHeaderName(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.AuthorizationHeader.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CacheValueUtf8, out IJsonDocument? _, out int _)) + { + SetCacheValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.Cache.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CacheDurationValueUtf8, out IJsonDocument? _, out int _)) + { + SetCacheDurationValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.CacheDuration.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CipherSuitesUtf8, out IJsonDocument? _, out int _)) + { + SetCipherSuites(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.ObjectInArrayArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableJwkSecurityValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableJwkSecurityValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.DisableJwkSecurity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OperationDebugUtf8, out IJsonDocument? _, out int _)) + { + SetOperationDebug(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.DebugEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScopesMatcherValueUtf8, out IJsonDocument? _, out int _)) + { + SetScopesMatcherValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Validator.ScopesMatcher.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.ObjectInArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.ObjectInArray.cs index a2dffbe3cb3..93aab787136 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.ObjectInArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.ObjectInArray.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public ObjectInArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.cs index 3adef7cb1b5..f6c3097e9d3 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ObjectInArrayArray.cs @@ -39,11 +39,13 @@ public readonly partial struct Validator public readonly partial struct ObjectInArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -122,6 +124,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -335,6 +352,12 @@ private void CheckValidInstance() public ObjectInArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.JsonStringArray.cs index 7e125835737..df6b121e5d7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.JsonStringArray.cs @@ -25,11 +25,13 @@ public readonly partial struct PropagateClaimsArrayArray public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.cs index e5fab1794e4..1b93104670a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.PropagateClaimsArrayArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Validator public readonly partial struct PropagateClaimsArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public PropagateClaimsArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.Mutable.cs index 571f7f7c3a0..480d2cfda58 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.Mutable.cs @@ -386,6 +386,31 @@ public void SetJwkLocalPath(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.cs index bb35bffd7e7..44acaffea77 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkLocalPath.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredAlgAndJwkLocalPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.Mutable.cs index ae8e7cc8c4e..1c6c93afc5f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.Mutable.cs @@ -386,6 +386,31 @@ public void SetJwkUrl(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.cs index 8f928a97f60..6bab5a8f919 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.RequiredAlgAndJwkUrl.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredAlgAndJwkUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SJsonStrinArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SJsonStrinArray.cs index caf01bcd556..8d748962ec9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SJsonStrinArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SJsonStrinArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Validator public readonly partial struct SJsonStrinArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public SJsonStrinArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ScopesMatcher.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ScopesMatcher.cs index fbc2f15d108..169193379f4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ScopesMatcher.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ScopesMatcher.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ScopesMatcher Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SecretSUrl.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SecretSUrl.cs index c1cc6a620f0..d6f572dd1b5 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SecretSUrl.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.SecretSUrl.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public SecretSUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ValidatorJArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ValidatorJArray.cs index 929fa24bcb7..544da2f1474 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ValidatorJArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.ValidatorJArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Validator public readonly partial struct ValidatorJArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public ValidatorJArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.cs index 47269f58019..71c0ab3181b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Validator.cs @@ -1110,6 +1110,12 @@ private void CheckValidInstance() public Validator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.VersionOfThisSyntax.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.VersionOfThisSyntax.cs index b6c6a6b976f..e955405fb9a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.VersionOfThisSyntax.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.VersionOfThisSyntax.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public VersionOfThisSyntax Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.JsonStringArray.cs index 99db9f7cbef..54e5f518f14 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct Virtualhost public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.Mutable.cs index 0cf348b5dcf..d47494376c8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.Mutable.cs @@ -260,6 +260,31 @@ public void SetHosts(in Corvus.KrakendBenchmark.Current.KrakendSchema. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.cs index 3c895d202e8..4ea64295230 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Virtualhost.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public Virtualhost Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.BackoffStrategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.BackoffStrategy.cs index b935221f03d..d45f0bef65d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.BackoffStrategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.BackoffStrategy.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public BackoffStrategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.DirectCommunicationNoMultiplexing.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.DirectCommunicationNoMultiplexing.cs index 4f67a74e9b4..68385da26d4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.DirectCommunicationNoMultiplexing.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.DirectCommunicationNoMultiplexing.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DirectCommunicationNoMultiplexing Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.JsonStringArray.cs index 95085c349f4..89e82b16610 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.JsonStringArray.cs @@ -39,11 +39,13 @@ public readonly partial struct Websocket public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaxRetries.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaxRetries.cs index 591e7987524..bf0b3b51a7f 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaxRetries.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaxRetries.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaxRetries Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaximumMessageSize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaximumMessageSize.cs index 15cfc540e7d..d5cca260130 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaximumMessageSize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MaximumMessageSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MaximumMessageSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MessageBufferSize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MessageBufferSize.cs index ee2c140e223..ff6e56679a9 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MessageBufferSize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.MessageBufferSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public MessageBufferSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.Mutable.cs index ce9cbede28a..c675c942ae8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.Mutable.cs @@ -1265,6 +1265,86 @@ public bool RemoveWriteWait() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackoffStrategyValueUtf8, out IJsonDocument? _, out int _)) + { + SetBackoffStrategyValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.BackoffStrategy.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConnectEventUtf8, out IJsonDocument? _, out int _)) + { + SetConnectEvent(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.NotifyConnections.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisconnectEventUtf8, out IJsonDocument? _, out int _)) + { + SetDisconnectEvent(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.NotifyDisconnections.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableDirectCommunicationUtf8, out IJsonDocument? _, out int _)) + { + SetEnableDirectCommunication(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.DirectCommunicationNoMultiplexing.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputHeadersUtf8, out IJsonDocument? _, out int _)) + { + SetInputHeaders(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxMessageSizeUtf8, out IJsonDocument? _, out int _)) + { + SetMaxMessageSize(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.MaximumMessageSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxRetriesValueUtf8, out IJsonDocument? _, out int _)) + { + SetMaxRetriesValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.MaxRetries.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MessageBufferSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetMessageBufferSizeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.MessageBufferSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReadBufferSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetReadBufferSizeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.ReadBufferSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReturnErrorDetailsValueUtf8, out IJsonDocument? _, out int _)) + { + SetReturnErrorDetailsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.ReturnErrorDetails.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WriteBufferSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetWriteBufferSizeValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Websocket.WriteBufferSize.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyConnections.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyConnections.cs index 3269146a96a..216f89bca12 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyConnections.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyConnections.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public NotifyConnections Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyDisconnections.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyDisconnections.cs index f6cc9089a9e..87ea27ceba1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyDisconnections.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.NotifyDisconnections.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public NotifyDisconnections Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReadBufferSize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReadBufferSize.cs index 5315763a2e9..a25efc1fd61 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReadBufferSize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReadBufferSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ReadBufferSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReturnErrorDetails.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReturnErrorDetails.cs index cd67572e245..fbfe89d93a8 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReturnErrorDetails.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.ReturnErrorDetails.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ReturnErrorDetails Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.WriteBufferSize.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.WriteBufferSize.cs index dc2ae73eadc..f07cafa10f1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.WriteBufferSize.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.WriteBufferSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public WriteBufferSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.cs index 67baf18ff96..8d6998afaae 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Websocket.cs @@ -787,6 +787,12 @@ private void CheckValidInstance() public Websocket Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.Mutable.cs index d5219682ec0..41aee4587f4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.Mutable.cs @@ -260,6 +260,31 @@ public void SetEndpoints(in Corvus.KrakendBenchmark.Current.JsonObject _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.cs index 2db6e1ccafb..366d21e4823 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Wildcard.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public Wildcard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.BackendArray.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.BackendArray.cs index 92761ff4e81..59a2ecd565d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.BackendArray.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.BackendArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Workflow public readonly partial struct BackendArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public BackendArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.ConcurrentCalls.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.ConcurrentCalls.cs index 13185ba7534..bedcbe00c33 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.ConcurrentCalls.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.ConcurrentCalls.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ConcurrentCalls Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.IgnoreErrors.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.IgnoreErrors.cs index 4efac5b0f9a..475976cf9d7 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.IgnoreErrors.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.IgnoreErrors.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public IgnoreErrors Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.Mutable.cs index 11494a985bf..089465f9318 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.Mutable.cs @@ -696,6 +696,52 @@ public bool RemoveTimeout() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConcurrentCallsValueUtf8, out IJsonDocument? _, out int _)) + { + SetConcurrentCallsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Workflow.ConcurrentCalls.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IgnoreErrorsValueUtf8, out IJsonDocument? _, out int _)) + { + SetIgnoreErrorsValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Workflow.IgnoreErrors.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputEncodingValueUtf8, out IJsonDocument? _, out int _)) + { + SetOutputEncodingValue(Corvus.KrakendBenchmark.Current.KrakendSchema.Workflow.OutputEncoding.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtraConfigUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.WorkflowExtraConfig.Mutable __corvusExtraConfig)) + { + __corvusExtraConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.OutputEncoding.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.OutputEncoding.cs index e26ff66a0b1..62b93906a4b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.OutputEncoding.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.OutputEncoding.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public OutputEncoding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.cs index 985c1003e6d..ad72a8c70a0 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.Workflow.cs @@ -564,6 +564,12 @@ private void CheckValidInstance() public Workflow Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Mutable.cs index 5cefd315caf..b646af4e779 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Mutable.cs @@ -1098,6 +1098,73 @@ public bool RemoveValidationJsonSchema() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierJmespathUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Jmespath.Mutable __corvusModifierJmespath)) + { + __corvusModifierJmespath.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierLuaProxyUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Lua.Mutable __corvusModifierLuaProxy)) + { + __corvusModifierLuaProxy.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierRequestBodyGeneratorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.Mutable __corvusModifierRequestBodyGenerator)) + { + __corvusModifierRequestBodyGenerator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModifierResponseBodyGeneratorUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.BodyGenerator.Mutable __corvusModifierResponseBodyGenerator)) + { + __corvusModifierResponseBodyGenerator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginReqRespModifierUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.ReqRespModifier.Mutable __corvusPluginReqRespModifier)) + { + __corvusPluginReqRespModifier.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProxyValueUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.WorkflowExtraConfig.Proxy.Mutable __corvusProxyValue)) + { + __corvusProxyValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecurityPoliciesUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.Policies.Mutable __corvusSecurityPolicies)) + { + __corvusSecurityPolicies.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.Mutable.cs index ea69e28aae7..2112f819750 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.Mutable.cs @@ -524,6 +524,42 @@ public bool RemoveStatic() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SequentialUtf8, out IJsonDocument? _, out int _)) + { + SetSequential(Corvus.KrakendBenchmark.Current.KrakendSchema.WorkflowExtraConfig.Proxy.SequentialProxy.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StaticUtf8, out Corvus.KrakendBenchmark.Current.KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Mutable __corvusStatic)) + { + __corvusStatic.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.SequentialProxy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.SequentialProxy.cs index f9e125148b2..b5e6e3ee81d 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.SequentialProxy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.SequentialProxy.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public SequentialProxy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Mutable.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Mutable.cs index 78546f4c7f7..eb8eea48300 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Mutable.cs @@ -323,6 +323,31 @@ public void SetStrategyValue(scoped in Corvus.KrakendBenchmark.Current.KrakendSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Strategy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Strategy.cs index 1a4efe18a4d..686ac3b9213 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Strategy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.Strategy.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public Strategy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.cs index a6ae7abddb3..f38e558424b 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.StaticResponse.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public StaticResponse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.cs index 54d82ccfea0..a7e1112fe32 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.Proxy.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public Proxy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.cs index 8568ef7ff9e..883f507cbf4 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.WorkflowExtraConfig.cs @@ -594,6 +594,12 @@ private void CheckValidInstance() public WorkflowExtraConfig Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.cs b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.cs index 7f4eb252d4d..e26338285d1 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.cs +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/KrakendSchema.cs @@ -1274,6 +1274,12 @@ private void CheckValidInstance() public KrakendSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/corvusjson-jsonschema.lock index 4cc97302842..930fbc3ee9a 100644 --- a/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.KrakendBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:36.4203546\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:18.1376351\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/JsonString.cs index 4122300280e..0d9987f07cd 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/JsonString.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf0Entity.cs index 8caf23fa64d..e25db7b2f69 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf1Entity.cs index 5002b5b5c3c..3310b420793 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.OneOf1Entity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.cs index 47796116d0b..3045f8b7e7f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Color.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public Color Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.ConfirmOnQuit.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.ConfirmOnQuit.cs index bbf71376f63..78b6fd71390 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.ConfirmOnQuit.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.ConfirmOnQuit.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public ConfirmOnQuit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.CustomCommandsPromptsTypeProperty.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.CustomCommandsPromptsTypeProperty.cs index b754200d0a8..39125bb3eb1 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.CustomCommandsPromptsTypeProperty.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.CustomCommandsPromptsTypeProperty.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public CustomCommandsPromptsTypeProperty Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.DisableStartupPopups.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.DisableStartupPopups.cs index 953e585ca45..df7e074a792 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.DisableStartupPopups.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.DisableStartupPopups.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DisableStartupPopups Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AllBranchesLogCmd.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AllBranchesLogCmd.cs index a740e92c708..5f874dd76c1 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AllBranchesLogCmd.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AllBranchesLogCmd.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public AllBranchesLogCmd Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoFetch.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoFetch.cs index ab7457c876f..f0c42108a84 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoFetch.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoFetch.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AutoFetch Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoRefresh.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoRefresh.cs index 307c74034d1..85ab7544af9 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoRefresh.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.AutoRefresh.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AutoRefresh Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.BranchLogCmd.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.BranchLogCmd.cs index 13a8967eaed..f893b709518 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.BranchLogCmd.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.BranchLogCmd.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public BranchLogCmd Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.Mutable.cs index 2452901df2b..c4d321428bf 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.Mutable.cs @@ -211,6 +211,36 @@ public bool RemoveSignOffValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SignOffValueUtf8, out IJsonDocument? _, out int _)) + { + SetSignOffValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Commit.SignOff.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.SignOff.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.SignOff.cs index a6616a2a885..3c9d4f16b4d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.SignOff.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.SignOff.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public SignOff Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.cs index 36840f9bfd8..47aa48b5c4c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Commit.cs @@ -301,6 +301,12 @@ private void CheckValidInstance() public Commit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Mutable.cs index cd94a0d6624..0e772dcb3a2 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Mutable.cs @@ -261,6 +261,31 @@ public void SetReplaceValue(scoped in Corvus.LazygitBenchmark.Current.LazygitSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Pattern.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Pattern.cs index 49984ac7726..14ef5b4aa61 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Pattern.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Pattern.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public Pattern Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Replace.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Replace.cs index 57e317d05f3..06f6d7bcb88 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Replace.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.Replace.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public Replace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.cs index bceda6d332c..43f4e4982bb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.RepositoryPath.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public RepositoryPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.cs index 3ffb386eac5..d36169b9fc1 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.CommitPrefixes.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public CommitPrefixes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DiffContextSize.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DiffContextSize.cs index f08cc61e262..3c9b4dcb51e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DiffContextSize.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DiffContextSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public DiffContextSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DisableForcePushing.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DisableForcePushing.cs index 7f15827e5f1..be05b6ae447 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DisableForcePushing.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.DisableForcePushing.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DisableForcePushing Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.FetchAll.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.FetchAll.cs index 0372bbfe25f..a962616839a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.FetchAll.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.FetchAll.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public FetchAll Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Mutable.cs index 7f0904bde59..194e0833ccb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Mutable.cs @@ -351,6 +351,46 @@ public bool RemoveShowWholeGraphValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OrderValueUtf8, out IJsonDocument? _, out int _)) + { + SetOrderValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Log.Order.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowGraphValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowGraphValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Log.ShowGraph.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowWholeGraphValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowWholeGraphValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Log.ShowWholeGraph.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Order.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Order.cs index 78d34bbd719..1542434210e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Order.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.Order.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public Order Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowGraph.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowGraph.cs index 0a458e52b1e..d88fdf8b07b 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowGraph.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowGraph.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public ShowGraph Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowWholeGraph.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowWholeGraph.cs index 59162903110..4eac58ce66f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowWholeGraph.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.ShowWholeGraph.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ShowWholeGraph Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.cs index fe52c883a9d..dcedfe54aad 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Log.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public Log Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.MainBranchesEntity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.MainBranchesEntity.cs index 1e473b5ec6d..725057d51b4 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.MainBranchesEntity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.MainBranchesEntity.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public MainBranchesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.cs index dea742ef76d..dd6b8b11d4c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.MainBranchesEntityArray.cs @@ -42,11 +42,13 @@ public readonly partial struct Git public readonly partial struct MainBranchesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -97,6 +99,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -310,6 +327,12 @@ private void CheckValidInstance() public MainBranchesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Arguments.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Arguments.cs index 931a80b71a6..454d034df84 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Arguments.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Arguments.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public Arguments Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.ManualCommit.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.ManualCommit.cs index 0d119d60bc0..7a55d7e8000 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.ManualCommit.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.ManualCommit.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ManualCommit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Mutable.cs index 29da3666fa1..469f7c20cff 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.Mutable.cs @@ -281,6 +281,41 @@ public bool RemoveManualCommitValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ArgsUtf8, out IJsonDocument? _, out int _)) + { + SetArgs(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Merging.Arguments.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ManualCommitValueUtf8, out IJsonDocument? _, out int _)) + { + SetManualCommitValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Merging.ManualCommit.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.cs index 8612d660d2a..68fccb596fa 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Merging.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Merging Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Mutable.cs index c632352adeb..f8f1e4e5cdb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Mutable.cs @@ -1475,6 +1475,110 @@ public bool RemoveSkipHookPrefixValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllBranchesLogCmdValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllBranchesLogCmdValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.AllBranchesLogCmd.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AutoFetchValueUtf8, out IJsonDocument? _, out int _)) + { + SetAutoFetchValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.AutoFetch.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AutoRefreshValueUtf8, out IJsonDocument? _, out int _)) + { + SetAutoRefreshValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.AutoRefresh.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BranchLogCmdValueUtf8, out IJsonDocument? _, out int _)) + { + SetBranchLogCmdValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.BranchLogCmd.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DiffContextSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetDiffContextSizeValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.DiffContextSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableForcePushingValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableForcePushingValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.DisableForcePushing.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FetchAllValueUtf8, out IJsonDocument? _, out int _)) + { + SetFetchAllValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.FetchAll.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MainBranchesUtf8, out IJsonDocument? _, out int _)) + { + SetMainBranches(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.MainBranchesEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OverrideGpgValueUtf8, out IJsonDocument? _, out int _)) + { + SetOverrideGpgValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.OverrideGpg.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ParseEmojiValueUtf8, out IJsonDocument? _, out int _)) + { + SetParseEmojiValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.ParseEmoji.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipHookPrefixValueUtf8, out IJsonDocument? _, out int _)) + { + SetSkipHookPrefixValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.SkipHookPrefix.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommitValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Commit.Mutable __corvusCommitValue)) + { + __corvusCommitValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LogValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Log.Mutable __corvusLogValue)) + { + __corvusLogValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MergingValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Merging.Mutable __corvusMergingValue)) + { + __corvusMergingValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PagingValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Paging.Mutable __corvusPagingValue)) + { + __corvusPagingValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.OverrideGpg.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.OverrideGpg.cs index 5969d11bc4f..73985f78832 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.OverrideGpg.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.OverrideGpg.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public OverrideGpg Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.ColorArgument.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.ColorArgument.cs index bec54e5e9e0..82d31d81622 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.ColorArgument.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.ColorArgument.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public ColorArgument Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Mutable.cs index 4d9626c8ed7..f2ec2b3f08d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Mutable.cs @@ -351,6 +351,41 @@ public bool RemoveUseConfigValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ColorArgUtf8, out IJsonDocument? _, out int _)) + { + SetColorArg(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Paging.ColorArgument.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseConfigValueUtf8, out IJsonDocument? _, out int _)) + { + SetUseConfigValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Paging.UseConfig.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Pager.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Pager.cs index c2fd516114d..cd67ec58d84 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Pager.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.Pager.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public Pager Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.UseConfig.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.UseConfig.cs index 81b8e4d5419..fadeac6dbaf 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.UseConfig.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.UseConfig.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public UseConfig Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.cs index 0351f3f71ed..352291b075e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.Paging.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public Paging Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.ParseEmoji.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.ParseEmoji.cs index cfb031e1f8d..12da86170a7 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.ParseEmoji.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.ParseEmoji.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ParseEmoji Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.SkipHookPrefix.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.SkipHookPrefix.cs index 1b523b9e0c6..25e6838fb2d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.SkipHookPrefix.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.SkipHookPrefix.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SkipHookPrefix Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.cs index cb93c97c071..0f5dd9bf3c6 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Git.cs @@ -674,6 +674,12 @@ private void CheckValidInstance() public Git Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AnimateExplosion.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AnimateExplosion.cs index 3202eb8de6f..1b67f9a1c20 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AnimateExplosion.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AnimateExplosion.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AnimateExplosion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AuthorColors.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AuthorColors.cs index 749a6c2dcee..aad8a569e03 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AuthorColors.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.AuthorColors.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public AuthorColors Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Border.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Border.cs index 09311cdd336..c9a12b17ae3 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Border.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Border.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Border Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.BranchColors.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.BranchColors.cs index 18a07d814f4..ddb5221a89d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.BranchColors.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.BranchColors.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public BranchColors Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommandLogSize.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommandLogSize.cs index ab8fe3c5325..53839ef802f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommandLogSize.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommandLogSize.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public CommandLogSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Mutable.cs index 990d1f39033..4c47cf5129e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Mutable.cs @@ -211,6 +211,36 @@ public bool RemoveShowValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.CommitLength.Show.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Show.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Show.cs index 2663baac4bb..9c52869fb76 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Show.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.Show.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public Show Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.cs index 1e7ba0e1ca0..3eb8efad86e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.CommitLength.cs @@ -301,6 +301,12 @@ private void CheckValidInstance() public CommitLength Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ExpandFocusedSidePanel.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ExpandFocusedSidePanel.cs index de44e89ceb0..1cf0bada5d8 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ExpandFocusedSidePanel.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ExpandFocusedSidePanel.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ExpandFocusedSidePanel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Language.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Language.cs index 3e429cf3010..7d958a17f6e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Language.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Language.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Language Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MainPanelSplitMode.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MainPanelSplitMode.cs index 92625386bdf..993c1feed4c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MainPanelSplitMode.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MainPanelSplitMode.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public MainPanelSplitMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MouseEvents.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MouseEvents.cs index d1da2fbae12..a4b92c83da2 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MouseEvents.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.MouseEvents.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public MouseEvents Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Mutable.cs index d30a93e612f..965031ace5d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Mutable.cs @@ -2246,6 +2246,163 @@ public bool RemoveWindowSizeValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AnimateExplosionValueUtf8, out IJsonDocument? _, out int _)) + { + SetAnimateExplosionValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.AnimateExplosion.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BorderValueUtf8, out IJsonDocument? _, out int _)) + { + SetBorderValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.Border.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommandLogSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetCommandLogSizeValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.CommandLogSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExpandFocusedSidePanelValueUtf8, out IJsonDocument? _, out int _)) + { + SetExpandFocusedSidePanelValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ExpandFocusedSidePanel.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LanguageValueUtf8, out IJsonDocument? _, out int _)) + { + SetLanguageValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.Language.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MainPanelSplitModeValueUtf8, out IJsonDocument? _, out int _)) + { + SetMainPanelSplitModeValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.MainPanelSplitMode.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MouseEventsValueUtf8, out IJsonDocument? _, out int _)) + { + SetMouseEventsValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.MouseEvents.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NerdFontsVersionValueUtf8, out IJsonDocument? _, out int _)) + { + SetNerdFontsVersionValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.NerdFontsVersion.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScrollHeightValueUtf8, out IJsonDocument? _, out int _)) + { + SetScrollHeightValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ScrollHeight.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScrollPastBottomValueUtf8, out IJsonDocument? _, out int _)) + { + SetScrollPastBottomValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ScrollPastBottom.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShortTimeFormatValueUtf8, out IJsonDocument? _, out int _)) + { + SetShortTimeFormatValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ShortTimeFormat.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowBottomLineValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowBottomLineValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ShowBottomLine.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowBranchCommitHashValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowBranchCommitHashValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ShowBranchCommitHash.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowCommandLogValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowCommandLogValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ShowCommandLog.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowFileTreeValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowFileTreeValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ShowFileTree.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowListFooterValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowListFooterValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ShowListFooter.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowRandomTipValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowRandomTipValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.ShowRandomTip.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SidePanelWidthValueUtf8, out IJsonDocument? _, out int _)) + { + SetSidePanelWidthValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.SidePanelWidth.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipDiscardChangeWarningValueUtf8, out IJsonDocument? _, out int _)) + { + SetSkipDiscardChangeWarningValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.SkipDiscardChangeWarning.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipRewordInEditorWarningValueUtf8, out IJsonDocument? _, out int _)) + { + SetSkipRewordInEditorWarningValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.SkipRewordInEditorWarning.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SkipStashWarningValueUtf8, out IJsonDocument? _, out int _)) + { + SetSkipStashWarningValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.SkipStashWarning.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SplitDiffValueUtf8, out IJsonDocument? _, out int _)) + { + SetSplitDiffValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.SplitDiff.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TimeFormatValueUtf8, out IJsonDocument? _, out int _)) + { + SetTimeFormatValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.TimeFormat.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WindowSizeValueUtf8, out IJsonDocument? _, out int _)) + { + SetWindowSizeValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.WindowSize.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommitLengthValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.CommitLength.Mutable __corvusCommitLengthValue)) + { + __corvusCommitLengthValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ThemeValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.Theme.Mutable __corvusThemeValue)) + { + __corvusThemeValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.NerdFontsVersion.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.NerdFontsVersion.cs index dae9c75a163..b1647b127c7 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.NerdFontsVersion.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.NerdFontsVersion.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public NerdFontsVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollHeight.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollHeight.cs index d7c8ce55658..35d0f64a6ee 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollHeight.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollHeight.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ScrollHeight Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollPastBottom.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollPastBottom.cs index 8c706f3fd65..fbcee2e5710 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollPastBottom.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ScrollPastBottom.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ScrollPastBottom Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShortTimeFormat.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShortTimeFormat.cs index da0525f9ca2..c1e789ef7ff 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShortTimeFormat.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShortTimeFormat.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public ShortTimeFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBottomLine.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBottomLine.cs index 074b3141776..cfb03e442ba 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBottomLine.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBottomLine.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ShowBottomLine Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBranchCommitHash.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBranchCommitHash.cs index 26db11fe275..3fd818b57ee 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBranchCommitHash.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowBranchCommitHash.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ShowBranchCommitHash Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowCommandLog.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowCommandLog.cs index bdccfeaa2f4..99d0c26c8f5 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowCommandLog.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowCommandLog.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ShowCommandLog Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowFileTree.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowFileTree.cs index b986cb9c792..4d3c2220cd7 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowFileTree.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowFileTree.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ShowFileTree Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowListFooter.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowListFooter.cs index 076f7ccfb02..d33cd39a64e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowListFooter.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowListFooter.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ShowListFooter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowRandomTip.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowRandomTip.cs index e6ff1e174bf..8001ca3ba39 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowRandomTip.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.ShowRandomTip.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ShowRandomTip Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SidePanelWidth.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SidePanelWidth.cs index 63367652b72..3e4079838db 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SidePanelWidth.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SidePanelWidth.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public SidePanelWidth Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipDiscardChangeWarning.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipDiscardChangeWarning.cs index b89dd76b3c2..fbf9d34d22d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipDiscardChangeWarning.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipDiscardChangeWarning.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SkipDiscardChangeWarning Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipRewordInEditorWarning.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipRewordInEditorWarning.cs index 8ec1fd43111..ae5f433cf65 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipRewordInEditorWarning.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipRewordInEditorWarning.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SkipRewordInEditorWarning Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipStashWarning.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipStashWarning.cs index c8fcea7cd4d..fbce27bb498 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipStashWarning.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SkipStashWarning.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SkipStashWarning Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SplitDiff.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SplitDiff.cs index bfabd4810c7..61ae974cf9a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SplitDiff.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.SplitDiff.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SplitDiff Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.CherrArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.CherrArray.cs index bc4119167a9..b02ae6b5730 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.CherrArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.CherrArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct CherrArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public CherrArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.ColorArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.ColorArray.cs index 7fcd00f6d28..595d0a16f75 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.ColorArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.ColorArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct ColorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public ColorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.DefauArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.DefauArray.cs index ed787756ec6..ca817b83b2f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.DefauArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.DefauArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct DefauArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public DefauArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.InactArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.InactArray.cs index 042c29ebf1c..22b41a671eb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.InactArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.InactArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct InactArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public InactArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.Mutable.cs index cf3cdd73efe..8b06eacff56 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.Mutable.cs @@ -1201,6 +1201,31 @@ public bool RemoveUnstagedChangesColor() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.OptioArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.OptioArray.cs index 4de63fd3ab5..47939a07bee 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.OptioArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.OptioArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct OptioArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public OptioArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SearcArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SearcArray.cs index bc2c6fa67e1..5069c343ef1 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SearcArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SearcArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct SearcArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public SearcArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SelecArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SelecArray.cs index baffef2f1e9..df55d0245b5 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SelecArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.SelecArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct SelecArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public SelecArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.UnstaArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.UnstaArray.cs index cbe6485ccc8..bb5757a7260 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.UnstaArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.UnstaArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Theme public readonly partial struct UnstaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public UnstaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.cs index da4ca5c315e..13406380c7c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.Theme.cs @@ -526,6 +526,12 @@ private void CheckValidInstance() public Theme Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.TimeFormat.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.TimeFormat.cs index 3fa9381215d..060a02b617a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.TimeFormat.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.TimeFormat.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TimeFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.WindowSize.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.WindowSize.cs index b3731fbf2ed..307ca58bfb3 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.WindowSize.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.WindowSize.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public WindowSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.cs index 9f8c5cdd2e7..73cca23f15a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Gui.cs @@ -977,6 +977,12 @@ private void CheckValidInstance() public Gui Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Keybinding.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Keybinding.cs index 7960faf009a..18c1e3dbb60 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Keybinding.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Keybinding.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public Keybinding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.Mutable.cs index d2f550a7d55..a500e1a0c78 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.Mutable.cs @@ -1051,6 +1051,31 @@ public bool RemoveViewPullRequestOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.cs index b826ce20c5c..c3bfb86c108 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Branches.cs @@ -601,6 +601,12 @@ private void CheckValidInstance() public Branches Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.Mutable.cs index 572d096d8b6..7c0d93ca21f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.Mutable.cs @@ -211,6 +211,31 @@ public bool RemoveCheckoutCommitFile() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.cs index 927163268fc..cf3c3d1c44a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.CommitFiles.cs @@ -301,6 +301,12 @@ private void CheckValidInstance() public CommitFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.Mutable.cs index 077834770e7..8912ed937d2 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.Mutable.cs @@ -1611,6 +1611,31 @@ public bool RemoveViewResetOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.cs index 07d98744fda..8ebc4e9c755 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Commits.cs @@ -801,6 +801,12 @@ private void CheckValidInstance() public Commits Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.Mutable.cs index 117d42d73cf..a6683b8693b 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.Mutable.cs @@ -1121,6 +1121,31 @@ public bool RemoveViewStashOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.cs index 58221d9af2d..8ed3d489336 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Files.cs @@ -626,6 +626,12 @@ private void CheckValidInstance() public Files Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.Mutable.cs index e9a8419d915..892029ecae4 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.Mutable.cs @@ -421,6 +421,31 @@ public bool RemoveToggleSelectHunk() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.cs index c6bb42238ed..71d92cfc2af 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Main.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public Main Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement
(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Mutable.cs index 296a444a003..1a2c0f1362f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Mutable.cs @@ -1093,6 +1093,85 @@ public bool RemoveUniversalValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BranchesValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Branches.Mutable __corvusBranchesValue)) + { + __corvusBranchesValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommitFilesValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.CommitFiles.Mutable __corvusCommitFilesValue)) + { + __corvusCommitFilesValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommitsValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Commits.Mutable __corvusCommitsValue)) + { + __corvusCommitsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilesValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Files.Mutable __corvusFilesValue)) + { + __corvusFilesValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MainValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Main.Mutable __corvusMainValue)) + { + __corvusMainValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StashValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Stash.Mutable __corvusStashValue)) + { + __corvusStashValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatusValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Status.Mutable __corvusStatusValue)) + { + __corvusStatusValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SubmodulesValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Submodules.Mutable __corvusSubmodulesValue)) + { + __corvusSubmodulesValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UniversalValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Universal.Mutable __corvusUniversalValue)) + { + __corvusUniversalValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.Mutable.cs index e24d4749554..8a448a85629 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveRenameStash() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.cs index 17092046b88..22c4f1dc834 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Stash.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Stash Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.Mutable.cs index 7397cfec2ac..85721937ebf 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveRecentRepos() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.cs index d17870bf8bd..4baa29cfcc9 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Status.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public Status Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.Mutable.cs index c32e5ddb9f0..53b3aef35fb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.Mutable.cs @@ -351,6 +351,31 @@ public bool RemoveUpdate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.cs index e9217c4a6ec..0891c69635d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Submodules.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public Submodules Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.JumpToBlock.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.JumpToBlock.cs index 2da5557a590..dca7c0fe9f4 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.JumpToBlock.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.JumpToBlock.cs @@ -47,11 +47,13 @@ public readonly partial struct Universal public readonly partial struct JumpToBlock #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -97,6 +99,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -310,6 +327,12 @@ private void CheckValidInstance() public JumpToBlock Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.Mutable.cs index 90fd04dad7a..b053534b0fd 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.Mutable.cs @@ -4307,6 +4307,41 @@ public bool RemoveUndo() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JumpToBlockValueUtf8, out IJsonDocument? _, out int _)) + { + SetJumpToBlockValue(Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Universal.JumpToBlock.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionMenuValueUtf8, out IJsonDocument? _, out int _)) + { + SetOptionMenuValue(Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Universal.OptionMenu.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.OptionMenu.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.OptionMenu.cs index 87ed36932f3..e1223aedbc5 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.OptionMenu.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.OptionMenu.cs @@ -279,6 +279,12 @@ private void CheckValidInstance() public OptionMenu Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.cs index 2cfc60f2446..297acd56198 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.Universal.cs @@ -1751,6 +1751,12 @@ private void CheckValidInstance() public Universal Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.cs index cd59792bf2a..86d9eed4d23 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.LazygitSchemaKeybinding.cs @@ -499,6 +499,12 @@ private void CheckValidInstance() public LazygitSchemaKeybinding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Mutable.cs index ddb8fed0de5..92e6f3e8dfc 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Mutable.cs @@ -1334,6 +1334,92 @@ public bool RemoveUpdateValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfirmOnQuitValueUtf8, out IJsonDocument? _, out int _)) + { + SetConfirmOnQuitValue(Corvus.LazygitBenchmark.Current.LazygitSchema.ConfirmOnQuit.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableStartupPopupsValueUtf8, out IJsonDocument? _, out int _)) + { + SetDisableStartupPopupsValue(Corvus.LazygitBenchmark.Current.LazygitSchema.DisableStartupPopups.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NotARepositoryValueUtf8, out IJsonDocument? _, out int _)) + { + SetNotARepositoryValue(Corvus.LazygitBenchmark.Current.LazygitSchema.NotARepository.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PromptToReturnFromSubprocessValueUtf8, out IJsonDocument? _, out int _)) + { + SetPromptToReturnFromSubprocessValue(Corvus.LazygitBenchmark.Current.LazygitSchema.PromptToReturnFromSubprocess.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.QuitOnTopLevelReturnValueUtf8, out IJsonDocument? _, out int _)) + { + SetQuitOnTopLevelReturnValue(Corvus.LazygitBenchmark.Current.LazygitSchema.QuitOnTopLevelReturn.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GitValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Git.Mutable __corvusGitValue)) + { + __corvusGitValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GuiValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Gui.Mutable __corvusGuiValue)) + { + __corvusGuiValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.KeybindingValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.LazygitSchemaKeybinding.Mutable __corvusKeybindingValue)) + { + __corvusKeybindingValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OsValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Os.Mutable __corvusOsValue)) + { + __corvusOsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RefresherValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Refresher.Mutable __corvusRefresherValue)) + { + __corvusRefresherValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UpdateValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.Update.Mutable __corvusUpdateValue)) + { + __corvusUpdateValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.NotARepository.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.NotARepository.cs index 69f91016f90..6bfbe901cf1 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.NotARepository.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.NotARepository.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public NotARepository Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.CopyToClipboardCmd.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.CopyToClipboardCmd.cs index 043701e3ecd..9c305f3a2f9 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.CopyToClipboardCmd.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.CopyToClipboardCmd.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public CopyToClipboardCmd Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Edit.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Edit.cs index e80c7c4d86e..d7105a39a50 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Edit.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Edit.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public Edit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLine.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLine.cs index 91572a67efe..82c21818794 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLine.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLine.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public EditAtLine Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLineAndWait.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLineAndWait.cs index bde9e6625ff..968990b9bdf 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLineAndWait.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditAtLineAndWait.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public EditAtLineAndWait Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf0Entity.cs index d66d904a7c1..675a49e9783 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf1Entity.cs index 72146065ad0..1e81078741c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.OneOf1Entity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.cs index 2863d6ede60..a20e9f36cf4 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.EditPreset.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public EditPreset Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Mutable.cs index 7e0da1837a6..5186ae29b8c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Mutable.cs @@ -629,6 +629,66 @@ public bool RemoveOpenLinkValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CopyToClipboardCmdValueUtf8, out IJsonDocument? _, out int _)) + { + SetCopyToClipboardCmdValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Os.CopyToClipboardCmd.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EditValueUtf8, out IJsonDocument? _, out int _)) + { + SetEditValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Os.Edit.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EditAtLineValueUtf8, out IJsonDocument? _, out int _)) + { + SetEditAtLineValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Os.EditAtLine.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EditAtLineAndWaitValueUtf8, out IJsonDocument? _, out int _)) + { + SetEditAtLineAndWaitValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Os.EditAtLineAndWait.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EditPresetValueUtf8, out IJsonDocument? _, out int _)) + { + SetEditPresetValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Os.EditPreset.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OpenValueUtf8, out IJsonDocument? _, out int _)) + { + SetOpenValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Os.Open.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OpenLinkValueUtf8, out IJsonDocument? _, out int _)) + { + SetOpenLinkValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Os.OpenLink.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Open.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Open.cs index bdb2188c332..7cfa1db4fcb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Open.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.Open.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Open Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.OpenLink.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.OpenLink.cs index dd142eddc1f..43d9e224099 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.OpenLink.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.OpenLink.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public OpenLink Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.cs index a78067c8375..8a1325d2075 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Os.cs @@ -449,6 +449,12 @@ private void CheckValidInstance() public Os Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.PromptToReturnFromSubprocess.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.PromptToReturnFromSubprocess.cs index 6e23cfecc66..95a4c698a0a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.PromptToReturnFromSubprocess.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.PromptToReturnFromSubprocess.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public PromptToReturnFromSubprocess Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.QuitOnTopLevelReturn.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.QuitOnTopLevelReturn.cs index 5df887e0ae6..66680aa95c3 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.QuitOnTopLevelReturn.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.QuitOnTopLevelReturn.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public QuitOnTopLevelReturn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.FetchInterval.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.FetchInterval.cs index 63d6507798c..9a42a9908f8 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.FetchInterval.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.FetchInterval.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public FetchInterval Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.Mutable.cs index 8ea0e3ea131..80b4e8304c3 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.Mutable.cs @@ -279,6 +279,41 @@ public bool RemoveRefreshIntervalValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FetchIntervalValueUtf8, out IJsonDocument? _, out int _)) + { + SetFetchIntervalValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Refresher.FetchInterval.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RefreshIntervalValueUtf8, out IJsonDocument? _, out int _)) + { + SetRefreshIntervalValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Refresher.RefreshInterval.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.RefreshInterval.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.RefreshInterval.cs index b41df1ee7fa..66a8be72ee2 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.RefreshInterval.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.RefreshInterval.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public RefreshInterval Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.cs index 3691486701e..bcdb05f4f33 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Refresher.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public Refresher Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.CheckForConflicts.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.CheckForConflicts.cs index dd9d9e8d882..d1dba658491 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.CheckForConflicts.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.CheckForConflicts.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public CheckForConflicts Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.Mutable.cs index 250d3cda8d1..e79663ae0a8 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.Mutable.cs @@ -213,6 +213,36 @@ public bool RemoveCheckForConflictsValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CheckForConflictsValueUtf8, out IJsonDocument? _, out int _)) + { + SetCheckForConflictsValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.CheckForConflicts.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.cs index 6b767643940..8600dcc6896 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public After Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Command.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Command.cs index 14b07ffd4d0..ad5544ac8de 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Command.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Command.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public Command Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Context.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Context.cs index ec743122623..2846ca7f95a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Context.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Context.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public Context Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Description.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Description.cs index 7668e09b55c..5bd2717cd9b 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Description.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Description.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public Description Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.LoadingText.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.LoadingText.cs index 06f0026155f..d2338ec513a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.LoadingText.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.LoadingText.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public LoadingText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Mutable.cs index e823b177ef9..27fd0022f7f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Mutable.cs @@ -880,6 +880,67 @@ public bool RemoveSubprocessValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommandValueUtf8, out IJsonDocument? _, out int _)) + { + SetCommandValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Command.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DescriptionValueUtf8, out IJsonDocument? _, out int _)) + { + SetDescriptionValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Description.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LoadingTextValueUtf8, out IJsonDocument? _, out int _)) + { + SetLoadingTextValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.LoadingText.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowOutputValueUtf8, out IJsonDocument? _, out int _)) + { + SetShowOutputValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StreamValueUtf8, out IJsonDocument? _, out int _)) + { + SetStreamValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Stream.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SubprocessValueUtf8, out IJsonDocument? _, out int _)) + { + SetSubprocessValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Subprocess.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AfterValueUtf8, out Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.After.Mutable __corvusAfterValue)) + { + __corvusAfterValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Requ_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Requ_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.cs index 065556e824e..bb76da9de91 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Requ_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Requ_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Require_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Require_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.Mutable.cs index cd51160c8a2..d9dbd3a15e2 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Require_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Require_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredK_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredK_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.cs index ff23f931276..61186b73ecf 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredK_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredK_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.cs @@ -41,11 +41,13 @@ public readonly partial struct RequiredOptions public readonly partial struct AnOptionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -95,6 +97,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -308,6 +325,12 @@ private void CheckValidInstance() public AnOptionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.TypeEntity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.TypeEntity.cs index 438c3c93e40..fe5ae12c228 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.TypeEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.Mutable.cs index 94d3edb269f..4712e62d0c9 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.Mutable.cs index aedd7b6ce85..7c698a1bc86 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.Mutable.cs @@ -449,6 +449,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.TypeEntity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.TypeEntity.cs index d427fe896d0..243234a1c8b 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.TypeEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.cs index 2dddc671e6b..f00b8de52e9 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public Command Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Mutable.cs index b96acd20976..5a38bd682ea 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Mutable.cs @@ -625,6 +625,51 @@ public bool RemoveValueFormatValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommandValueUtf8, out IJsonDocument? _, out int _)) + { + SetCommandValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilterValueUtf8, out IJsonDocument? _, out int _)) + { + SetFilterValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LabelFormatValueUtf8, out IJsonDocument? _, out int _)) + { + SetLabelFormatValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueFormatValueUtf8, out IJsonDocument? _, out int _)) + { + SetValueFormatValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Suggestions.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Suggestions.cs index a850305cc6e..9f863fb1152 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Suggestions.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Suggestions.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public Suggestions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.cs index ad5b45510e8..95501da19fd 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public Filter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.Mutable.cs index 7ce0a8afc41..207c2850f98 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitl_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitl_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.Mutable.cs index dfc82a44988..712cc0752cb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitl_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitl_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Mutable.cs index 8f6c247c85f..6076370e65f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Mutable.cs @@ -532,6 +532,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.Mutable.cs index cd2aa5cef1b..a7a83ed2e7a 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.Mutable.cs @@ -426,6 +426,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeA_._AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeA_._AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.cs index 07c9af1b9dd..045532426fd 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeA_._AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeA_._AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.cs @@ -363,6 +363,12 @@ private void CheckValidInstance() public AnOption Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._RequiredOptions.AnOptionArray.AnOption.Description.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._RequiredOptions.AnOptionArray.AnOption.Description.cs index 645006f06db..d7aa879f9fc 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._RequiredOptions.AnOptionArray.AnOption.Description.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._RequiredOptions.AnOptionArray.AnOption.Description.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public Description Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf0Entity.cs index cde613ab117..737b9fa83ce 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf0Entity.cs @@ -305,6 +305,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf1Entity.cs index acc37c2a485..c57d7b2588f 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf1Entity.cs @@ -305,6 +305,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.Mutable.cs index 29cc8292aa5..1052604d164 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.Mutable.cs @@ -603,6 +603,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.cs index 23201ad1838..d79f4a7b435 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.cs @@ -469,6 +469,12 @@ private void CheckValidInstance() public AllOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.Mutable.cs index 7317a636d2a..a2c77179535 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.Mutable.cs @@ -497,6 +497,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.cs index b10345c11b2..99cfc74f775 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.Mutable.cs index 47b4743d103..4e904e0ca4b 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.Mutable.cs @@ -533,6 +533,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.cs index 7ba8576b327..3ea7255e723 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public AllOf2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.Mutable.cs index 9ed6b402352..3d390a81fa3 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.Mutable.cs @@ -707,6 +707,51 @@ public bool RemoveValueFormat() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommandUtf8, out IJsonDocument? _, out int _)) + { + SetCommand(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilterUtf8, out IJsonDocument? _, out int _)) + { + SetFilter(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LabelFormatUtf8, out IJsonDocument? _, out int _)) + { + SetLabelFormat(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueFormatUtf8, out IJsonDocument? _, out int _)) + { + SetValueFormat(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.cs index 319461102cc..0c5f9591569 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.cs @@ -519,6 +519,12 @@ private void CheckValidInstance() public AllOf3Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.Mutable.cs index 05ffc1fd257..33cfcc46e58 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.Mutable.cs @@ -1096,6 +1096,51 @@ public bool RemoveValueFormat() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommandUtf8, out IJsonDocument? _, out int _)) + { + SetCommand(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilterUtf8, out IJsonDocument? _, out int _)) + { + SetFilter(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LabelFormatUtf8, out IJsonDocument? _, out int _)) + { + SetLabelFormat(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueFormatUtf8, out IJsonDocument? _, out int _)) + { + SetValueFormat(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.cs index 632f3b83d06..2e1ba1f4e22 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.cs @@ -706,6 +706,12 @@ private void CheckValidInstance() public RequiredKeyAndTitleAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.cs index fff521f464f..82b9ccde130 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.cs @@ -33,11 +33,13 @@ public readonly partial struct RequiredCommandAndContextAndKey public readonly partial struct RequiredKeyAndTitleAndTypeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public RequiredKeyAndTitleAndTypeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._RequiredOptions.AnOptionArray.AnOption.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._RequiredOptions.AnOptionArray.AnOption.Mutable.cs index 1a463602914..a2c7c60571d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._RequiredOptions.AnOptionArray.AnOption.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._RequiredOptions.AnOptionArray.AnOption.Mutable.cs @@ -352,6 +352,41 @@ public void SetValueValue(scoped in Corvus.LazygitBenchmark.Current.LazygitSchem _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DescriptionValueUtf8, out IJsonDocument? _, out int _)) + { + SetDescriptionValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.Description.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NameValueUtf8, out IJsonDocument? _, out int _)) + { + SetNameValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.Name.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.RequiredOptions.AnOptionArray.AnOption.Name.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.RequiredOptions.AnOptionArray.AnOption.Name.cs index 72480827fb6..2effe9f076e 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.RequiredOptions.AnOptionArray.AnOption.Name.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.RequiredOptions.AnOptionArray.AnOption.Name.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf0Entity.Mutable.cs index 11628051aed..4489d5d51cc 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf0Entity.Mutable.cs @@ -223,6 +223,31 @@ public bool RemovePresetValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Command.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Command.cs index 94eaa45eca0..fbb6421a223 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Command.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Command.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public Command Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Mutable.cs index 85c3d90ff5b..a535afb24e0 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Mutable.cs @@ -223,6 +223,36 @@ public bool RemoveCommandValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommandValueUtf8, out IJsonDocument? _, out int _)) + { + SetCommandValue(Corvus.LazygitBenchmark.Current.LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Suggestions.OneOf1Entity.Command.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._tity.ThenEntity.Suggestions.OneOf0Entity.Preset.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._tity.ThenEntity.Suggestions.OneOf0Entity.Preset.cs index c8bdf5ac755..88357567cf7 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._tity.ThenEntity.Suggestions.OneOf0Entity.Preset.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._tity.ThenEntity.Suggestions.OneOf0Entity.Preset.cs @@ -337,6 +337,12 @@ private void CheckValidInstance() public Preset Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ty.RequiredOptions.AnOptionArray.AnOption.Value.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ty.RequiredOptions.AnOptionArray.AnOption.Value.cs index 94204f7d5f8..a106f5ea7a4 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ty.RequiredOptions.AnOptionArray.AnOption.Value.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ty.RequiredOptions.AnOptionArray.AnOption.Value.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public Value Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.TypeEntity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.TypeEntity.cs index 92e74002572..3db952666f0 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.TypeEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.cs index 327a109335c..f8d782fa4c2 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public LabelFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.cs index ced35f72fb6..849e021dfa5 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public ValueFormat Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.cs index 8cd95d37c54..a198b562f83 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ShowOutput Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Stream.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Stream.cs index f22f711209f..f5616c34ec0 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Stream.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Stream.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public Stream Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Subprocess.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Subprocess.cs index 7982b9a1b98..54edac7653d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Subprocess.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Subprocess.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public Subprocess Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.cs index b7e19669f28..bd1f52b8f7c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.cs @@ -535,6 +535,12 @@ private void CheckValidInstance() public RequiredCommandAndContextAndKey Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.cs index a9076efbb87..bd2744d06a2 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public WithTypeConfirm Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.cs index ae6f5a4fe96..c98a2fa960d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public RequiredOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.cs index c312e53c3c8..eca18a60879 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.cs @@ -451,6 +451,12 @@ private void CheckValidInstance() public RequiredCommand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._edKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._edKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.cs index 77b1fc49a2c..aa3f9c143f8 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._edKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._edKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public WithTypeInput Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._redKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._redKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.cs index a4a7f4432a7..72fd32b8e20 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._redKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._redKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public WithTypeMenu Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._tleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._tleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.cs index bb25c97e35f..b8b7c7a70ab 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._tleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._tleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public WithTypeMenuFromCommand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.cs index 805ca9c3361..791eba4037d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.cs index d69ecc2d5e7..c1e6b214f46 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.cs index eea088743dc..a3cf4964718 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.RequiredCommandAndContextAndKeyArray.cs @@ -29,11 +29,13 @@ public readonly partial struct LazygitSchema public readonly partial struct RequiredCommandAndContextAndKeyArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -83,6 +85,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -296,6 +313,12 @@ private void CheckValidInstance() public RequiredCommandAndContextAndKeyArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.Service.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.Service.cs index 223f85f31cb..d8901ee1e70 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.Service.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.Service.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public Service Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.cs index b613a34adef..01b2b2708bd 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Services.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public Services Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Days.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Days.cs index 57050c2ca85..cca51bdc8a9 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Days.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Days.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public Days Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Method.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Method.cs index f1b8a3453a8..fe04ccb2147 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Method.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Method.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public Method Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Mutable.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Mutable.cs index c3b2c16ba78..9074cfb094c 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.Mutable.cs @@ -279,6 +279,41 @@ public bool RemoveMethodValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DaysValueUtf8, out IJsonDocument? _, out int _)) + { + SetDaysValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Update.Days.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MethodValueUtf8, out IJsonDocument? _, out int _)) + { + SetMethodValue(Corvus.LazygitBenchmark.Current.LazygitSchema.Update.Method.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.cs index 196e506f3fb..0074d2933bb 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.Update.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public Update Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.cs b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.cs index 043be41df64..ab64d43e07d 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.cs +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/LazygitSchema.cs @@ -596,6 +596,12 @@ private void CheckValidInstance() public LazygitSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/corvusjson-jsonschema.lock index f9e29d38787..af6ff67c8fa 100644 --- a/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.LazygitBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:37.4956360\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:20.3742093\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { @@ -369,90 +369,98 @@ "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.LoadingText.Mutable.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.LoadingText.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Requ_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Requ_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Require_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredK_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.TypeEntity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.TypeEntity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndT_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Suggestions.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitl_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndT_._AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTyp_._AllOf2Entity.RequiredOptions.AnOptionArray.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeA_._AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeA_._AllOf3Entity.RequiredCommand.LabelFormat.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeA_._AllOf3Entity.RequiredCommand.ValueFormat.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._AllOf1Entity.WithTypeConfirm.TypeEntity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._AllOf2Entity.RequiredOptions.AnOptionArray.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._RequiredOptions.AnOptionArray.AnOption.Description.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArr_._RequiredOptions.AnOptionArray.AnOption.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf0Entity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.ThenEntity.Suggestions.OneOf1Entity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf0Entity.WithTypeInput.TypeEntity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf3Entity.RequiredCommand.LabelFormat.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf3Entity.RequiredCommand.ValueFormat.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredK_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredK_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyA_._RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTi_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.TypeEntity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTit_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.TypeEntity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Command.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleA_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAn_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Suggestions.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAn_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.Filter.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndT_._RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTyp_._AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTyp_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTyp_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeAr_._AllOf3Entity.WithTypeMenuFromCommand.TypeEntity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArra_._AllOf2Entity.RequiredOptions.AnOptionArray.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.R_._ThenEntity.Suggestions.OneOf0Entity.Preset.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.Mutable.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.Mutable.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf0Entity.ThenEntity.Suggestions.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf1Entity.WithTypeConfirm.TypeEntity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf2Entity.WithTypeMenu.TypeEntity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf3Entity.RequiredCommand.Command.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf3Entity.RequiredCommand.Filter.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._Entity.Suggestions.OneOf1Entity.Command.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._Options.AnOptionArray.AnOption.Value.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._RequiredOptions.AnOptionArray.AnOption.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ThenEntity.Suggestions.OneOf0Entity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ThenEntity.Suggestions.OneOf1Entity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._dOptions.AnOptionArray.AnOption.Name.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._e.AllOf0Entity.WithTypeInput.TypeEntity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ions.AnOptionArray.AnOption.Description.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._iredOptions.AnOptionArray.AnOption.Name.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.RequiredOptions.AnOptionArray.AnOption.Name.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.Suggestions.OneOf1Entity.Command.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf0Entity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Command.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ity.ThenEntity.Suggestions.OneOf1Entity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._nEntity.Suggestions.OneOf0Entity.Preset.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._pe.AllOf2Entity.WithTypeMenu.TypeEntity.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._pe.AllOf3Entity.RequiredCommand.Command.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._redOptions.AnOptionArray.AnOption.Value.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._s.AnOptionArray.AnOption.Description.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._tity.Suggestions.OneOf0Entity.Preset.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._tity.ThenEntity.Suggestions.OneOf0Entity.Preset.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ty.RequiredOptions.AnOptionArray.AnOption.Value.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ype.AllOf0Entity.ThenEntity.Suggestions.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ype.AllOf3Entity.RequiredCommand.Filter.Mutable.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.TypeEntity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.LabelFormat.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKey_._RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.ValueFormat.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._2Entity.RequiredOptions.AnOptionArray.AnOption.Value.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf2Entity.RequiredOptions.AnOptionArray.AnOption.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf3Entity.RequiredCommand.LabelFormat.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AllOf3Entity.RequiredCommand.ValueFormat.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AndType.AllOf2Entity.WithTypeMenu.TypeEntity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._AndType.AllOf3Entity.RequiredCommand.Command.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._Of0Entity.ThenEntity.Suggestions.OneOf0Entity.Preset.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._RequiredOptions.AnOptionArray.AnOption.Name.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._RequiredOptions.AnOptionArray.AnOption.Value.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ThenEntity.Suggestions.OneOf1Entity.Command.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._Type.AllOf1Entity.WithTypeConfirm.TypeEntity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._Type.AllOf2Entity.WithTypeMenu.TypeEntity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._Type.AllOf3Entity.RequiredCommand.Command.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._dType.AllOf0Entity.ThenEntity.Suggestions.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._dType.AllOf3Entity.RequiredCommand.Filter.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._e.AllOf1Entity.WithTypeConfirm.TypeEntity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._e.AllOf2Entity.RequiredOptions.AnOptionArray.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._eAndType.AllOf0Entity.ThenEntity.Suggestions.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._eAndType.AllOf3Entity.RequiredCommand.Filter.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._edOptions.AnOptionArray.AnOption.Description.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._enEntity.Suggestions.OneOf1Entity.Command.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._f0Entity.ThenEntity.Suggestions.OneOf0Entity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._f0Entity.ThenEntity.Suggestions.OneOf1Entity.Command.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._f0Entity.ThenEntity.Suggestions.OneOf1Entity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._f2Entity.RequiredOptions.AnOptionArray.AnOption.Name.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._henEntity.Suggestions.OneOf0Entity.Preset.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ndType.AllOf0Entity.WithTypeInput.TypeEntity.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ntity.RequiredOptions.AnOptionArray.AnOption.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ntity.ThenEntity.Suggestions.OneOf0Entity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ntity.ThenEntity.Suggestions.OneOf1Entity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ptions.AnOptionArray.AnOption.Description.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._quiredOptions.AnOptionArray.AnOption.Name.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ty.RequiredOptions.AnOptionArray.AnOption.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._uiredOptions.AnOptionArray.AnOption.Value.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._y.RequiredOptions.AnOptionArray.AnOption.Description.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ype.AllOf0Entity.ThenEntity.Suggestions.OneOf0Entity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ype.AllOf0Entity.ThenEntity.Suggestions.OneOf1Entity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ype.AllOf0Entity.WithTypeInput.TypeEntity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ype.AllOf3Entity.RequiredCommand.LabelFormat.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAndTypeArray_._ype.AllOf3Entity.RequiredCommand.ValueFormat.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAnd_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.Mutable.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitleAnd_._RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitle_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAndTitle_._RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.TypeEntity.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.RequiredKeyAnd_._RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.AnOptionArray.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.JsonSchema.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.Mutable.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.ShowOutput.cs", @@ -463,18 +471,10 @@ "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Subprocess.Mutable.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.Subprocess.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._KeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._edKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.WithTypeInput.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._redKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.WithTypeMenu.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._tleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf0Entity.ThenEntity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.ThenEntity.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.JsonSchema.cs", - "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.JsonSchema.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._AndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.WithTypeMenuFromCommand.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf1Entity.WithTypeConfirm.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf2Entity.RequiredOptions.cs", + "LazygitSchema.RequiredCommandAndContextAndKeyArray.RequiredCommandAndContextAndKey_._uiredKeyAndTitleAndTypeArray.RequiredKeyAndTitleAndType.AllOf3Entity.RequiredCommand.cs", "LazygitSchema.RequiredCommandAndContextAndKeyArray.cs", "LazygitSchema.Services.JsonSchema.cs", "LazygitSchema.Services.Mutable.cs", diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonBoolean.cs index aaedac85f96..a8c96bb9060 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonString.cs index 1e5abe7a49a..5b2ed87cf89 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.ArrayOfGloArray.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.ArrayOfGloArray.cs index 125032c2bef..f972183a69f 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.ArrayOfGloArray.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.ArrayOfGloArray.cs @@ -26,11 +26,13 @@ public readonly partial struct LernaSchema public readonly partial struct ArrayOfGloArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ArrayOfGloArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.JsonStringArray.cs index 828f226bc36..779760729fd 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.JsonStringArray.cs @@ -26,11 +26,13 @@ public readonly partial struct LernaSchema public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.Mutable.cs index 32833970987..03365cfccbc 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.Mutable.cs @@ -917,6 +917,37 @@ public bool RemoveWorkspaces() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CommandUtf8, out Corvus.LernaBenchmark.Current.LernaSchema.OptionsForTheCliCommands.Mutable __corvusCommand)) + { + __corvusCommand.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.NpmClientAArray.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.NpmClientAArray.cs index e38704ae46f..2d2bdc9c971 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.NpmClientAArray.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.NpmClientAArray.cs @@ -26,11 +26,13 @@ public readonly partial struct LernaSchema public readonly partial struct NpmClientAArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public NpmClientAArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.Mutable.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.Mutable.cs index d0dabec4ffd..058c75b759d 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.Mutable.cs @@ -722,6 +722,61 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BootstrapUtf8, out Corvus.LernaBenchmark.Current.LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.Mutable __corvusBootstrap)) + { + __corvusBootstrap.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InitUtf8, out Corvus.LernaBenchmark.Current.LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.Mutable __corvusInit)) + { + __corvusInit.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PublishUtf8, out Corvus.LernaBenchmark.Current.LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.Mutable __corvusPublish)) + { + __corvusPublish.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RunUtf8, out Corvus.LernaBenchmark.Current.LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.Mutable __corvusRun)) + { + __corvusRun.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionUtf8, out Corvus.LernaBenchmark.Current.LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.Mutable __corvusVersion)) + { + __corvusVersion.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.IgnoreArray.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.IgnoreArray.cs index 097a08c688d..0181ec93f14 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.IgnoreArray.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.IgnoreArray.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public IgnoreArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.JsonStringArray.cs index 565b95131a5..839618db6bb 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct OptionsForTheBootstrapCommand public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.Mutable.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.Mutable.cs index 6807c261b6b..9aae4855adb 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.Mutable.cs @@ -418,6 +418,31 @@ public bool RemoveNpmClientArgs() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.cs index 82914d29f6d..df75cd2e1b3 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheBootstrapCommand.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public OptionsForTheBootstrapCommand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.Mutable.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.Mutable.cs index 9ceb0c43478..80facd3ff24 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.Mutable.cs @@ -280,6 +280,31 @@ public bool RemoveExact() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.cs index 2ac6f7247c9..a2e6d16354a 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheInitCommand.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public OptionsForTheInitCommand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.IgnoreChangesArray.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.IgnoreChangesArray.cs index d8bf3618671..4a1d1f65808 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.IgnoreChangesArray.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.IgnoreChangesArray.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public IgnoreChangesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.Mutable.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.Mutable.cs index d79f9fa8136..dd151916e2a 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.Mutable.cs @@ -382,6 +382,31 @@ public bool RemoveMessage() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.cs index 2558ccc3b05..f91fc70a23e 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForThePublishCommand.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public OptionsForThePublishCommand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.Mutable.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.Mutable.cs index fc46c283905..07b106a4aea 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.Mutable.cs @@ -280,6 +280,31 @@ public bool RemoveNpmClient() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.cs index e71aa45014a..1c8ab45ba24 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheRunCommand.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public OptionsForTheRunCommand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.AllowBranchArray.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.AllowBranchArray.cs index 5405e02644b..15b3fdc0a6f 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.AllowBranchArray.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.AllowBranchArray.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public AllowBranchArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.Mutable.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.Mutable.cs index 6786bccac4e..29a0317a408 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.Mutable.cs @@ -382,6 +382,31 @@ public bool RemoveMessage() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.cs index 6f120aaa31d..0978004f0da 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.OptionsForTheVersionCommand.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public OptionsForTheVersionCommand Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.cs index 91aecc0ee5e..fc0549baa64 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.OptionsForTheCliCommands.cs @@ -449,6 +449,12 @@ private void CheckValidInstance() public OptionsForTheCliCommands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.cs b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.cs index a62d0071ca1..88c4a26e7cb 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.cs +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/LernaSchema.cs @@ -512,6 +512,12 @@ private void CheckValidInstance() public LernaSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/corvusjson-jsonschema.lock index 686208b7d94..9e2155315a0 100644 --- a/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.LernaBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:38.3862081\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:21.9884387\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonBoolean.cs index 0a944a20508..929f8bfc7bc 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonString.cs index 8b6a023b8c1..77f2d64cb9f 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.Mutable.cs index 2c94d3200f8..bb1b3819b6e 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.Mutable.cs @@ -530,6 +530,31 @@ public bool RemoveWatchAssets() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.cs index 77cbb6c6e86..1f6b88612ad 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.AssetsOptions.cs @@ -482,6 +482,12 @@ private void CheckValidInstance() public AssetsOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CollectionEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CollectionEntity.cs index a499a78e5fc..c8e8d9c6e5e 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CollectionEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CollectionEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public CollectionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.AssetsOptionsArray.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.AssetsOptionsArray.cs index 9422129a4b2..60bc8ba508d 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.AssetsOptionsArray.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.AssetsOptionsArray.cs @@ -36,11 +36,13 @@ public readonly partial struct CompilerOptions public readonly partial struct AssetsOptionsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public AssetsOptionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf0Entity.cs index 4f49ac9f8d8..a7fb40f7019 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf0Entity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.Mutable.cs index 9145d229d29..65ec9024dbf 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.Mutable.cs @@ -379,6 +379,42 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypeUtf8, out IJsonDocument? _, out int _)) + { + SetType(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.TypeEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionsUtf8, out Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.Mutable __corvusOptions)) + { + __corvusOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.ArrayOfFilArray.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.ArrayOfFilArray.cs index 1bfc07c1c89..e5b30b48f4f 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.ArrayOfFilArray.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.ArrayOfFilArray.cs @@ -34,11 +34,13 @@ public readonly partial struct OptionsEntity public readonly partial struct ArrayOfFilArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public ArrayOfFilArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.JsonStringArray.cs index 77fb355bac0..9a840dd40a8 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.JsonStringArray.cs @@ -34,11 +34,13 @@ public readonly partial struct OptionsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.Mutable.cs index 32354fb6a62..a596ecc1b67 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.Mutable.cs @@ -818,6 +818,31 @@ public bool RemoveWatch() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.cs index 00e3814abf1..381c27ce109 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.OptionsEntity.cs @@ -513,6 +513,12 @@ private void CheckValidInstance() public OptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.TypeEntity.cs index 4c8f2057c88..2ec79d133de 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.TypeEntity.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.cs index faca79e3f31..c6eb925e667 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.AnyOf1Entity.cs @@ -380,6 +380,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.cs index 49f21518e98..c259f1fee9a 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.BuilderEntity.cs @@ -449,6 +449,12 @@ private void CheckValidInstance() public BuilderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.DeleteOutDirEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.DeleteOutDirEntity.cs index 530da5f024e..e5d88d782f2 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.DeleteOutDirEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.DeleteOutDirEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DeleteOutDirEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.ManualRestartEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.ManualRestartEntity.cs index 248fe39108f..d7dbf5f38eb 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.ManualRestartEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.ManualRestartEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ManualRestartEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.Mutable.cs index 7367d5fc8ea..20d1bfe0c34 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.Mutable.cs @@ -907,6 +907,76 @@ public bool RemoveWebpackConfigPath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AssetsUtf8, out IJsonDocument? _, out int _)) + { + SetAssets(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.AssetsOptionsArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeleteOutDirUtf8, out IJsonDocument? _, out int _)) + { + SetDeleteOutDir(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.DeleteOutDirEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ManualRestartUtf8, out IJsonDocument? _, out int _)) + { + SetManualRestart(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.ManualRestartEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginsUtf8, out IJsonDocument? _, out int _)) + { + SetPlugins(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.PluginItemsArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TsConfigPathUtf8, out IJsonDocument? _, out int _)) + { + SetTsConfigPath(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.TsConfigPathEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypeCheckUtf8, out IJsonDocument? _, out int _)) + { + SetTypeCheck(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.TypeCheckEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WatchAssetsUtf8, out IJsonDocument? _, out int _)) + { + SetWatchAssets(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.WatchAssetsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WebpackUtf8, out IJsonDocument? _, out int _)) + { + SetWebpack(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.WebpackEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WebpackConfigPathUtf8, out IJsonDocument? _, out int _)) + { + SetWebpackConfigPath(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.WebpackConfigPathEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.PluginItemsArray.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.PluginItemsArray.cs index 45d4770754f..db6fd966c48 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.PluginItemsArray.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.PluginItemsArray.cs @@ -33,11 +33,13 @@ public readonly partial struct CompilerOptions public readonly partial struct PluginItemsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public PluginItemsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TsConfigPathEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TsConfigPathEntity.cs index ae6830fba30..49d32b4e6ad 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TsConfigPathEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TsConfigPathEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TsConfigPathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TypeCheckEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TypeCheckEntity.cs index f5cdb68685c..8f99da5b372 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TypeCheckEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.TypeCheckEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public TypeCheckEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WatchAssetsEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WatchAssetsEntity.cs index d1d8e1fd026..ca15c789910 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WatchAssetsEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WatchAssetsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WatchAssetsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackConfigPathEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackConfigPathEntity.cs index 831b20e8aae..d5f5a36123d 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackConfigPathEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackConfigPathEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public WebpackConfigPathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackEntity.cs index 434ac72832b..0ee96b9ec7a 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.WebpackEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WebpackEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.cs index af23c03f385..0581bd5a350 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.CompilerOptions.cs @@ -480,6 +480,12 @@ private void CheckValidInstance() public CompilerOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.DefaultImportPrefixForNewlyGeneratedLibraries.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.DefaultImportPrefixForNewlyGeneratedLibraries.cs index f7e4e87c71b..ed79648637f 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.DefaultImportPrefixForNewlyGeneratedLibraries.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.DefaultImportPrefixForNewlyGeneratedLibraries.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public DefaultImportPrefixForNewlyGeneratedLibraries Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateBaseDirOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateBaseDirOptions.cs index 0c73fa9106a..b4640701a44 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateBaseDirOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateBaseDirOptions.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public GenerateBaseDirOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateFlatOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateFlatOptions.cs index 21e532a560f..cb9b21f42d7 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateFlatOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateFlatOptions.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public GenerateFlatOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.Mutable.cs index aca90f45e09..ba7f06c105c 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.Mutable.cs @@ -383,6 +383,47 @@ public bool RemoveSpec() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BaseDirUtf8, out IJsonDocument? _, out int _)) + { + SetBaseDir(Corvus.NestCliBenchmark.Current.NestCliSchema.GenerateBaseDirOptions.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FlatUtf8, out IJsonDocument? _, out int _)) + { + SetFlat(Corvus.NestCliBenchmark.Current.NestCliSchema.GenerateFlatOptions.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpecUtf8, out Corvus.NestCliBenchmark.Current.NestCliSchema.GenerateSpecOptions.Mutable __corvusSpec)) + { + __corvusSpec.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.cs index fd6448c9cb4..9f8918e0d6f 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateOptions.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public GenerateOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.Mutable.cs index 2b90fb24081..1d6593315a2 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.Mutable.cs @@ -2630,6 +2630,31 @@ public bool RemoveSubApp() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.cs index 70a5a181062..58e66fb17a1 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GenerateSpecOptions.cs @@ -1142,6 +1142,12 @@ private void CheckValidInstance() public GenerateSpecOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.Mutable.cs index f17371e086f..fe50000bd67 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.Mutable.cs @@ -314,6 +314,36 @@ public bool RemoveTypeFileNameSuffix() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypeFileNameSuffixUtf8, out IJsonDocument? _, out int _)) + { + SetTypeFileNameSuffix(Corvus.NestCliBenchmark.Current.NestCliSchema.GraphQlPluginOptions.TypeFileNameSuffixArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.TypeFileNameSuffixArray.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.TypeFileNameSuffixArray.cs index 837b9647111..cd4f3c3eb7b 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.TypeFileNameSuffixArray.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.TypeFileNameSuffixArray.cs @@ -36,11 +36,13 @@ public readonly partial struct GraphQlPluginOptions public readonly partial struct TypeFileNameSuffixArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public TypeFileNameSuffixArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.cs index 505ccc76b12..9f91ec9a372 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.GraphQlPluginOptions.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public GraphQlPluginOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.LanguageEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.LanguageEntity.cs index e11a15342cd..7f418a64107 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.LanguageEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.LanguageEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public LanguageEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.MonorepoEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.MonorepoEntity.cs index f0b53e3ab5f..39478e91646 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.MonorepoEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.MonorepoEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public MonorepoEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.Mutable.cs index f0f3971b6fd..97b113f697b 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.Mutable.cs @@ -967,6 +967,93 @@ public bool RemoveSourceRoot() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CollectionUtf8, out IJsonDocument? _, out int _)) + { + SetCollection(Corvus.NestCliBenchmark.Current.NestCliSchema.CollectionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompilerOptionsValueUtf8, out IJsonDocument? _, out int _)) + { + SetCompilerOptionsValue(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultLibraryPrefixUtf8, out IJsonDocument? _, out int _)) + { + SetDefaultLibraryPrefix(Corvus.NestCliBenchmark.Current.NestCliSchema.DefaultImportPrefixForNewlyGeneratedLibraries.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EntryFileUtf8, out IJsonDocument? _, out int _)) + { + SetEntryFile(Corvus.NestCliBenchmark.Current.NestCliSchema.TheEntryFileWhereNestStartWorkWithDefaultToMain.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GenerateOptionsValueUtf8, out IJsonDocument? _, out int _)) + { + SetGenerateOptionsValue(Corvus.NestCliBenchmark.Current.NestCliSchema.GenerateOptions.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LanguageUtf8, out IJsonDocument? _, out int _)) + { + SetLanguage(Corvus.NestCliBenchmark.Current.NestCliSchema.LanguageEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MonorepoUtf8, out IJsonDocument? _, out int _)) + { + SetMonorepo(Corvus.NestCliBenchmark.Current.NestCliSchema.MonorepoEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProjectsUtf8, out IJsonDocument? _, out int _)) + { + SetProjects(Corvus.NestCliBenchmark.Current.NestCliSchema.ProjectsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RootUtf8, out IJsonDocument? _, out int _)) + { + SetRoot(Corvus.NestCliBenchmark.Current.NestCliSchema.RootEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SourceRootUtf8, out IJsonDocument? _, out int _)) + { + SetSourceRoot(Corvus.NestCliBenchmark.Current.NestCliSchema.SourceRootEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompilerOptionsValueUtf8, out Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.Mutable __corvusCompilerOptionsValue)) + { + __corvusCompilerOptionsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GenerateOptionsValueUtf8, out Corvus.NestCliBenchmark.Current.NestCliSchema.GenerateOptions.Mutable __corvusGenerateOptionsValue)) + { + __corvusGenerateOptionsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.Mutable.cs index e3bd7030577..c66ea72e530 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.Mutable.cs @@ -429,6 +429,31 @@ public bool RemoveOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.OptionsEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.OptionsEntity.cs index 1ba8a7ea6ff..231d54bfc73 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.OptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.OptionsEntity.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public OptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.cs index 3b7c358d8df..7f85065643a 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginItems.cs @@ -430,6 +430,12 @@ private void CheckValidInstance() public PluginItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.IntrospectCommentsEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.IntrospectCommentsEntity.cs index 311b06ad267..2db31fa51e9 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.IntrospectCommentsEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.IntrospectCommentsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IntrospectCommentsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.Mutable.cs index dd87ab9d061..64c527d1126 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.Mutable.cs @@ -278,6 +278,36 @@ public bool RemoveIntrospectComments() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IntrospectCommentsUtf8, out IJsonDocument? _, out int _)) + { + SetIntrospectComments(Corvus.NestCliBenchmark.Current.NestCliSchema.PluginOptions.IntrospectCommentsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.cs index 0dfb821818d..9cff2512a90 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.PluginOptions.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public PluginOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.Mutable.cs index 2df96ec5412..b817bc793bc 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.Mutable.cs @@ -587,6 +587,53 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompilerOptionsValueUtf8, out IJsonDocument? _, out int _)) + { + SetCompilerOptionsValue(Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GenerateOptionsValueUtf8, out IJsonDocument? _, out int _)) + { + SetGenerateOptionsValue(Corvus.NestCliBenchmark.Current.NestCliSchema.GenerateOptions.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompilerOptionsValueUtf8, out Corvus.NestCliBenchmark.Current.NestCliSchema.CompilerOptions.Mutable __corvusCompilerOptionsValue)) + { + __corvusCompilerOptionsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GenerateOptionsValueUtf8, out Corvus.NestCliBenchmark.Current.NestCliSchema.GenerateOptions.Mutable __corvusGenerateOptionsValue)) + { + __corvusGenerateOptionsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.cs index 992ba51809b..54e5f4ac6f0 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectConfiguration.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public ProjectConfiguration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectsEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectsEntity.cs index cb4e8b1ef38..07ceb7df23b 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectsEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.ProjectsEntity.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public ProjectsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.RootEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.RootEntity.cs index f09f854e16f..bb99a52c5bf 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.RootEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.RootEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public RootEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SourceRootEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SourceRootEntity.cs index 8dde3707f77..7829ab59e73 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SourceRootEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SourceRootEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public SourceRootEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ClassValidatorShimEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ClassValidatorShimEntity.cs index 3b8819c25e4..76ba0c597ad 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ClassValidatorShimEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ClassValidatorShimEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ClassValidatorShimEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerFileNameSuffixEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerFileNameSuffixEntity.cs index 3e57c283be9..0bef85a70e7 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerFileNameSuffixEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerFileNameSuffixEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ControllerFileNameSuffixEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerKeyOfCommentEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerKeyOfCommentEntity.cs index c42d7a20759..fe685396041 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerKeyOfCommentEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.ControllerKeyOfCommentEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ControllerKeyOfCommentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.DtoKeyOfCommentEntity.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.DtoKeyOfCommentEntity.cs index 54def797d24..fcca6ef09cc 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.DtoKeyOfCommentEntity.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.DtoKeyOfCommentEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public DtoKeyOfCommentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.JsonStringArray.cs index 430bd291568..96a13468f65 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.JsonStringArray.cs @@ -36,11 +36,13 @@ public readonly partial struct SwaggerPluginOptions public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.Mutable.cs index 78a3412f790..1867fabc115 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.Mutable.cs @@ -578,6 +578,56 @@ public bool RemoveDtoKeyOfComment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ClassValidatorShimUtf8, out IJsonDocument? _, out int _)) + { + SetClassValidatorShim(Corvus.NestCliBenchmark.Current.NestCliSchema.SwaggerPluginOptions.ClassValidatorShimEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ControllerFileNameSuffixUtf8, out IJsonDocument? _, out int _)) + { + SetControllerFileNameSuffix(Corvus.NestCliBenchmark.Current.NestCliSchema.SwaggerPluginOptions.ControllerFileNameSuffixEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ControllerKeyOfCommentUtf8, out IJsonDocument? _, out int _)) + { + SetControllerKeyOfComment(Corvus.NestCliBenchmark.Current.NestCliSchema.SwaggerPluginOptions.ControllerKeyOfCommentEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DtoFileNameSuffixUtf8, out IJsonDocument? _, out int _)) + { + SetDtoFileNameSuffix(Corvus.NestCliBenchmark.Current.NestCliSchema.SwaggerPluginOptions.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DtoKeyOfCommentUtf8, out IJsonDocument? _, out int _)) + { + SetDtoKeyOfComment(Corvus.NestCliBenchmark.Current.NestCliSchema.SwaggerPluginOptions.DtoKeyOfCommentEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.cs index 272cbf8eae4..64bff47814b 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.SwaggerPluginOptions.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public SwaggerPluginOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.TheEntryFileWhereNestStartWorkWithDefaultToMain.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.TheEntryFileWhereNestStartWorkWithDefaultToMain.cs index e31e21313e1..a6fba3cbf78 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.TheEntryFileWhereNestStartWorkWithDefaultToMain.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.TheEntryFileWhereNestStartWorkWithDefaultToMain.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public TheEntryFileWhereNestStartWorkWithDefaultToMain Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.cs b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.cs index 128d30129d2..3eae3d32b6a 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.cs +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/NestCliSchema.cs @@ -536,6 +536,12 @@ private void CheckValidInstance() public NestCliSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/corvusjson-jsonschema.lock index 977a729f99e..e1900e6b5bf 100644 --- a/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.NestCliBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:39.3370891\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:23.6971760\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/JsonString.cs index 66e4b53ec2d..20b3a12ca51 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.JsonStringArray.cs index c78b7a6a393..3cd08b32d7a 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.JsonStringArray.cs @@ -36,11 +36,13 @@ public readonly partial struct FileOptionsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.Mutable.cs index 0400050a56a..13052cb99b9 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.Mutable.cs @@ -416,6 +416,41 @@ public bool RemoveSystemExcludeSearchPatterns() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExcludeSearchPatternsUtf8, out IJsonDocument? _, out int _)) + { + SetExcludeSearchPatterns(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.FileOptionsEntity.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SystemExcludeSearchPatternsUtf8, out IJsonDocument? _, out int _)) + { + SetSystemExcludeSearchPatterns(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.FileOptionsEntity.RecommendeArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.RecommendeArray.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.RecommendeArray.cs index 8a0a0509681..7257cd140f2 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.RecommendeArray.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.RecommendeArray.cs @@ -41,11 +41,13 @@ public readonly partial struct FileOptionsEntity public readonly partial struct RecommendeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -96,6 +98,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -309,6 +326,12 @@ private void CheckValidInstance() public RecommendeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.cs index c86f38627ec..1bca4305ee5 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.FileOptionsEntity.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public FileOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.InsertionBehaviorEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.InsertionBehaviorEntity.cs index 1dc5de90a75..18e7d41516d 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.InsertionBehaviorEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.InsertionBehaviorEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public InsertionBehaviorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.Mutable.cs index 2441a888400..94956955af3 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.Mutable.cs @@ -334,6 +334,41 @@ public bool RemovePropertyGenerationBehavior() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InsertionBehaviorUtf8, out IJsonDocument? _, out int _)) + { + SetInsertionBehavior(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.ImplementTypeOptionsEntity.InsertionBehaviorEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropertyGenerationBehaviorUtf8, out IJsonDocument? _, out int _)) + { + SetPropertyGenerationBehavior(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.ImplementTypeOptionsEntity.PropertyGenerationBehaviorEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.PropertyGenerationBehaviorEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.PropertyGenerationBehaviorEntity.cs index 7b1ee4a0d9c..91ec55d44a8 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.PropertyGenerationBehaviorEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.PropertyGenerationBehaviorEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public PropertyGenerationBehaviorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.cs index c4aa7bab333..a7c80041ebf 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.ImplementTypeOptionsEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public ImplementTypeOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.Mutable.cs index f4ad4822a36..a05b70dfdf7 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.Mutable.cs @@ -1112,6 +1112,85 @@ public bool RemoveScript() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FileOptionsUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.FileOptionsEntity.Mutable __corvusFileOptions)) + { + __corvusFileOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FormattingOptionsUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.Mutable __corvusFormattingOptions)) + { + __corvusFormattingOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImplementTypeOptionsUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.ImplementTypeOptionsEntity.Mutable __corvusImplementTypeOptions)) + { + __corvusImplementTypeOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginsUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.PluginsEntity.Mutable __corvusPlugins)) + { + __corvusPlugins.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RenameOptionsUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RenameOptionsEntity.Mutable __corvusRenameOptions)) + { + __corvusRenameOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoslynExtensionsOptionsUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RoslynExtensionsOptionsEntity.Mutable __corvusRoslynExtensionsOptions)) + { + __corvusRoslynExtensionsOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CakeUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCakeCakeFiles.Mutable __corvusCake)) + { + __corvusCake.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MsbuildUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.Mutable __corvusMsbuild)) + { + __corvusMsbuild.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ScriptUtf8, out Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.Mutable __corvusScript)) + { + __corvusScript.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.JsonStringArray.cs index 8bc937c25dd..3dbd0fd83cb 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.JsonStringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct PluginsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.Mutable.cs index 96e96c9355a..8dd53281e72 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.Mutable.cs @@ -309,6 +309,36 @@ public bool RemoveLocationPaths() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LocationPathsUtf8, out IJsonDocument? _, out int _)) + { + SetLocationPaths(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.PluginsEntity.JsonStringArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.cs index 46db44b7980..6260b49e37d 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.PluginsEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public PluginsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.Mutable.cs index f44701774f8..4548f604349 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.Mutable.cs @@ -395,6 +395,46 @@ public bool RemoveRenameOverloads() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RenameInCommentsUtf8, out IJsonDocument? _, out int _)) + { + SetRenameInComments(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RenameOptionsEntity.RenameInCommentsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RenameInStringsUtf8, out IJsonDocument? _, out int _)) + { + SetRenameInStrings(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RenameOptionsEntity.RenameInStringsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RenameOverloadsUtf8, out IJsonDocument? _, out int _)) + { + SetRenameOverloads(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RenameOptionsEntity.RenameOverloadsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInCommentsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInCommentsEntity.cs index 07639b25751..34ac3d8ea93 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInCommentsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInCommentsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RenameInCommentsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInStringsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInStringsEntity.cs index e49d01911a7..facb0a266b1 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInStringsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameInStringsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RenameInStringsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameOverloadsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameOverloadsEntity.cs index 596ce951062..6ce79d7e417 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameOverloadsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.RenameOverloadsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RenameOverloadsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.cs index 89199581834..ea4bfce4273 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RenameOptionsEntity.cs @@ -387,6 +387,12 @@ private void CheckValidInstance() public RenameOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.DocumentAnalysisTimeoutMsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.DocumentAnalysisTimeoutMsEntity.cs index d2e6c6775b8..35880f1d619 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.DocumentAnalysisTimeoutMsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.DocumentAnalysisTimeoutMsEntity.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public DocumentAnalysisTimeoutMsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.EnableDecompilationSupportEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.EnableDecompilationSupportEntity.cs index cb85e729352..a18733510cc 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.EnableDecompilationSupportEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.EnableDecompilationSupportEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnableDecompilationSupportEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.IfSetToFalseOnlyRefactoringsAreAvailable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.IfSetToFalseOnlyRefactoringsAreAvailable.cs index a008a18c50c..9306152eeef 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.IfSetToFalseOnlyRefactoringsAreAvailable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.IfSetToFalseOnlyRefactoringsAreAvailable.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IfSetToFalseOnlyRefactoringsAreAvailable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.LocationPathsArray.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.LocationPathsArray.cs index d30d8cdbe2a..b78f8c5e0de 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.LocationPathsArray.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.LocationPathsArray.cs @@ -295,6 +295,12 @@ private void CheckValidInstance() public LocationPathsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.Mutable.cs index feec58c6887..592482c95c7 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.Mutable.cs @@ -497,6 +497,51 @@ public bool RemoveLocationPaths() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentAnalysisTimeoutMsUtf8, out IJsonDocument? _, out int _)) + { + SetDocumentAnalysisTimeoutMs(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RoslynExtensionsOptionsEntity.DocumentAnalysisTimeoutMsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableAnalyzersSupportUtf8, out IJsonDocument? _, out int _)) + { + SetEnableAnalyzersSupport(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RoslynExtensionsOptionsEntity.IfSetToFalseOnlyRefactoringsAreAvailable.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableDecompilationSupportUtf8, out IJsonDocument? _, out int _)) + { + SetEnableDecompilationSupport(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RoslynExtensionsOptionsEntity.EnableDecompilationSupportEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LocationPathsUtf8, out IJsonDocument? _, out int _)) + { + SetLocationPaths(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.RoslynExtensionsOptionsEntity.LocationPathsArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.cs index 549a3538697..d97a53ad7b5 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.RoslynExtensionsOptionsEntity.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public RoslynExtensionsOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.AnyOf0Entity.cs index e5beb392c20..717f5b3757a 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.AnyOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.cs index 3ca2a6e353f..9e77b2b5144 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public DefaultTargetFrameworkEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnableScriptNuGetReferencesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnableScriptNuGetReferencesEntity.cs index 458c096beb7..6a995c97d1c 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnableScriptNuGetReferencesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnableScriptNuGetReferencesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnableScriptNuGetReferencesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnabledEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnabledEntity.cs index 6e2d87a3fed..dbcddfa01dd 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnabledEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnabledEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnabledEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.Mutable.cs index e9ec42a6fe4..f6b25f604a2 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.Mutable.cs @@ -461,6 +461,51 @@ public bool RemoveRspFilePath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultTargetFrameworkUtf8, out IJsonDocument? _, out int _)) + { + SetDefaultTargetFramework(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.DefaultTargetFrameworkEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableScriptNuGetReferencesUtf8, out IJsonDocument? _, out int _)) + { + SetEnableScriptNuGetReferences(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnableScriptNuGetReferencesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.EnabledEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RspFilePathUtf8, out IJsonDocument? _, out int _)) + { + SetRspFilePath(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.RspFilePathEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.RspFilePathEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.RspFilePathEntity.cs index 7b6f8f0aa18..04815d292e1 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.RspFilePathEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.RspFilePathEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public RspFilePathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.cs index 120f60851ad..ca0921434bd 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCScriptingCsxFiles.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public UsedToConfigureCScriptingCsxFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.BakeryPathEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.BakeryPathEntity.cs index 77e37a48989..91dd7b7157b 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.BakeryPathEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.BakeryPathEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public BakeryPathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.EnabledEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.EnabledEntity.cs index c5b1d681052..5f6b2c4e36d 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.EnabledEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.EnabledEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnabledEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.Mutable.cs index e8ed651aa85..ab47c27bc3d 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.Mutable.cs @@ -334,6 +334,41 @@ public bool RemoveEnabled() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BakeryPathUtf8, out IJsonDocument? _, out int _)) + { + SetBakeryPath(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCakeCakeFiles.BakeryPathEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureCakeCakeFiles.EnabledEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.cs index 286685aad9d..ea67f3eb563 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureCakeCakeFiles.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public UsedToConfigureCakeCakeFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.AnyOf0Entity.cs index 469c5f82584..d8db27e2471 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.AnyOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.cs index e060b746dff..0c2a0ad01bc 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public BuildConfigurationUsedForProjectEvaluation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnablePackageAutoRestoreEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnablePackageAutoRestoreEntity.cs index 967ba17fbd6..ab1a5349507 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnablePackageAutoRestoreEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnablePackageAutoRestoreEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnablePackageAutoRestoreEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnabledEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnabledEntity.cs index 531bdcfd6ed..44616093e20 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnabledEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnabledEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnabledEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.FileNameOfCCompiler.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.FileNameOfCCompiler.cs index 4a5ccc40679..63a6c8e17cc 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.FileNameOfCCompiler.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.FileNameOfCCompiler.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public FileNameOfCCompiler Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LoadProjectsOnDemandEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LoadProjectsOnDemandEntity.cs index 05799484add..b4b696ebca7 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LoadProjectsOnDemandEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LoadProjectsOnDemandEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public LoadProjectsOnDemandEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LocalRoslynPathEGMsBuildPathCurrentBinRoslyn.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LocalRoslynPathEGMsBuildPathCurrentBinRoslyn.cs index a6c2f3ce243..46586f23df8 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LocalRoslynPathEGMsBuildPathCurrentBinRoslyn.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LocalRoslynPathEGMsBuildPathCurrentBinRoslyn.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public LocalRoslynPathEGMsBuildPathCurrentBinRoslyn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.MsBuildExtensionsPathEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.MsBuildExtensionsPathEntity.cs index 28bb65570fb..bd25850b328 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.MsBuildExtensionsPathEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.MsBuildExtensionsPathEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public MsBuildExtensionsPathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.Mutable.cs index c8d377ec9fa..115ac9eaf29 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.Mutable.cs @@ -1050,6 +1050,96 @@ public bool RemoveLoadProjectsOnDemand() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigurationUtf8, out IJsonDocument? _, out int _)) + { + SetConfiguration(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.BuildConfigurationUsedForProjectEvaluation.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CscToolExeUtf8, out IJsonDocument? _, out int _)) + { + SetCscToolExe(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.FileNameOfCCompiler.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CscToolPathUtf8, out IJsonDocument? _, out int _)) + { + SetCscToolPath(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LocalRoslynPathEGMsBuildPathCurrentBinRoslyn.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnablePackageAutoRestoreUtf8, out IJsonDocument? _, out int _)) + { + SetEnablePackageAutoRestore(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnablePackageAutoRestoreEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MsBuildExtensionsPathUtf8, out IJsonDocument? _, out int _)) + { + SetMsBuildExtensionsPath(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.MsBuildExtensionsPathEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MsBuildSdKsPathUtf8, out IJsonDocument? _, out int _)) + { + SetMsBuildSdKsPath(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PathToTheSdksFolderForThisMsBuildInstance.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PlatformUtf8, out IJsonDocument? _, out int _)) + { + SetPlatform(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoslynTargetsPathUtf8, out IJsonDocument? _, out int _)) + { + SetRoslynTargetsPath(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.RoslynTargetsPathEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TargetFrameworkRootPathUtf8, out IJsonDocument? _, out int _)) + { + SetTargetFrameworkRootPath(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.TargetFrameworkRootPathEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ToolsVersionUtf8, out IJsonDocument? _, out int _)) + { + SetToolsVersion(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VisualStudioVersionUtf8, out IJsonDocument? _, out int _)) + { + SetVisualStudioVersion(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.VisualStudioVersionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.EnabledEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LoadProjectsOnDemandUtf8, out IJsonDocument? _, out int _)) + { + SetLoadProjectsOnDemand(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.LoadProjectsOnDemandEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PathToTheSdksFolderForThisMsBuildInstance.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PathToTheSdksFolderForThisMsBuildInstance.cs index 1177d4f722f..f91db6d790d 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PathToTheSdksFolderForThisMsBuildInstance.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PathToTheSdksFolderForThisMsBuildInstance.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public PathToTheSdksFolderForThisMsBuildInstance Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.AnyOf0Entity.cs index 93265be23b8..113c3d6e6be 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.AnyOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.cs index 88a9bcbe242..0d33ded1e83 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.PlatformEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public PlatformEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.RoslynTargetsPathEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.RoslynTargetsPathEntity.cs index bf1b1f1d65c..54e8cbf42f6 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.RoslynTargetsPathEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.RoslynTargetsPathEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public RoslynTargetsPathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.TargetFrameworkRootPathEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.TargetFrameworkRootPathEntity.cs index 4033a846c4d..53f5ed91d24 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.TargetFrameworkRootPathEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.TargetFrameworkRootPathEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TargetFrameworkRootPathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.AnyOf0Entity.cs index b7f7fdff8ce..fa84bafb60b 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.AnyOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.cs index d8901362e39..a56c8b90c3f 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.ToolsVersionEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public ToolsVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.VisualStudioVersionEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.VisualStudioVersionEntity.cs index 400c1105cbc..3fb7d0aaacd 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.VisualStudioVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.VisualStudioVersionEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public VisualStudioVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.cs index c6fd928ca9f..52034f941b5 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToConfigureMsBuildSolutionsAndProjects.cs @@ -597,6 +597,12 @@ private void CheckValidInstance() public UsedToConfigureMsBuildSolutionsAndProjects Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.EnableEditorConfigSupportEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.EnableEditorConfigSupportEntity.cs index a631efa6bd9..f7f060fcfd6 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.EnableEditorConfigSupportEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.EnableEditorConfigSupportEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public EnableEditorConfigSupportEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBlockEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBlockEntity.cs index f73d60c586b..61a1f10e7eb 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBlockEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBlockEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public IndentBlockEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBracesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBracesEntity.cs index c90f24f74be..fda61542145 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBracesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentBracesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public IndentBracesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionEntity.cs index f60ff6760b0..95a56e4cfc9 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public IndentSwitchCaseSectionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionWhenBlockEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionWhenBlockEntity.cs index 772333b2da6..6387937c34b 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionWhenBlockEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionWhenBlockEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public IndentSwitchCaseSectionWhenBlockEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchSectionEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchSectionEntity.cs index 7f419eb52e4..ff3459ca2f6 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchSectionEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentSwitchSectionEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public IndentSwitchSectionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentationSizeEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentationSizeEntity.cs index 682f994a909..3d766362a09 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentationSizeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.IndentationSizeEntity.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public IndentationSizeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.LabelPositioningEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.LabelPositioningEntity.cs index fee0b75b014..3f4fa2e3206 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.LabelPositioningEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.LabelPositioningEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public LabelPositioningEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.Mutable.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.Mutable.cs index a99ba32b175..78830709861 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.Mutable.cs @@ -3384,6 +3384,291 @@ public bool RemoveWrappingPreserveSingleLine() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableEditorConfigSupportUtf8, out IJsonDocument? _, out int _)) + { + SetEnableEditorConfigSupport(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.EnableEditorConfigSupportEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentBlockUtf8, out IJsonDocument? _, out int _)) + { + SetIndentBlock(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.IndentBlockEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentBracesUtf8, out IJsonDocument? _, out int _)) + { + SetIndentBraces(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.IndentBracesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentSwitchCaseSectionUtf8, out IJsonDocument? _, out int _)) + { + SetIndentSwitchCaseSection(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentSwitchCaseSectionWhenBlockUtf8, out IJsonDocument? _, out int _)) + { + SetIndentSwitchCaseSectionWhenBlock(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.IndentSwitchCaseSectionWhenBlockEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentSwitchSectionUtf8, out IJsonDocument? _, out int _)) + { + SetIndentSwitchSection(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.IndentSwitchSectionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentationSizeUtf8, out IJsonDocument? _, out int _)) + { + SetIndentationSize(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.IndentationSizeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LabelPositioningUtf8, out IJsonDocument? _, out int _)) + { + SetLabelPositioning(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.LabelPositioningEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLineUtf8, out IJsonDocument? _, out int _)) + { + SetNewLine(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLineEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLineForCatchUtf8, out IJsonDocument? _, out int _)) + { + SetNewLineForCatch(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLineForCatchEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLineForClausesInQueryUtf8, out IJsonDocument? _, out int _)) + { + SetNewLineForClausesInQuery(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLineForClausesInQueryEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLineForElseUtf8, out IJsonDocument? _, out int _)) + { + SetNewLineForElse(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLineForElseEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLineForFinallyUtf8, out IJsonDocument? _, out int _)) + { + SetNewLineForFinally(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLineForFinallyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLineForMembersInAnonymousTypesUtf8, out IJsonDocument? _, out int _)) + { + SetNewLineForMembersInAnonymousTypes(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInAnonymousTypesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLineForMembersInObjectInitUtf8, out IJsonDocument? _, out int _)) + { + SetNewLineForMembersInObjectInit(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInObjectInitEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInAccessorsUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInAccessors(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAccessorsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInAnonymousMethodsUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInAnonymousMethods(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousMethodsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInAnonymousTypesUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInAnonymousTypes(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousTypesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInControlBlocksUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInControlBlocks(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInControlBlocksEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInLambdaExpressionBodyUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInLambdaExpressionBody(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInLambdaExpressionBodyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInMethodsUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInMethods(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInMethodsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInObjectCollectionArrayInitializersUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInObjectCollectionArrayInitializers(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInObjectCollectionArrayInitializersEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInPropertiesUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInProperties(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInPropertiesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewLinesForBracesInTypesUtf8, out IJsonDocument? _, out int _)) + { + SetNewLinesForBracesInTypes(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInTypesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceAfterCastUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceAfterCast(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCastEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceAfterColonInBaseTypeDeclarationUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceAfterColonInBaseTypeDeclaration(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceAfterColonInBaseTypeDeclarationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceAfterCommaUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceAfterComma(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCommaEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceAfterControlFlowStatementKeywordUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceAfterControlFlowStatementKeyword(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceAfterControlFlowStatementKeywordEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceAfterDotUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceAfterDot(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceAfterDotEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceAfterMethodCallNameUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceAfterMethodCallName(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceAfterMethodCallNameEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceAfterSemicolonsInForStatementUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceAfterSemicolonsInForStatement(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceAfterSemicolonsInForStatementEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBeforeColonInBaseTypeDeclarationUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBeforeColonInBaseTypeDeclaration(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeColonInBaseTypeDeclarationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBeforeCommaUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBeforeComma(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeCommaEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBeforeDotUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBeforeDot(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeDotEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBeforeOpenSquareBracketUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBeforeOpenSquareBracket(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeOpenSquareBracketEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBeforeSemicolonsInForStatementUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBeforeSemicolonsInForStatement(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeSemicolonsInForStatementEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBetweenEmptyMethodCallParenthesesUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBetweenEmptyMethodCallParentheses(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodCallParenthesesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBetweenEmptyMethodDeclarationParenthesesUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBetweenEmptyMethodDeclarationParentheses(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodDeclarationParenthesesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceBetweenEmptySquareBracketsUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceBetweenEmptySquareBrackets(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptySquareBracketsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceWithinCastParenthesesUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceWithinCastParentheses(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceWithinCastParenthesesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceWithinExpressionParenthesesUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceWithinExpressionParentheses(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceWithinExpressionParenthesesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceWithinMethodCallParenthesesUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceWithinMethodCallParentheses(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodCallParenthesesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceWithinMethodDeclarationParenthesisUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceWithinMethodDeclarationParenthesis(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodDeclarationParenthesisEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceWithinOtherParenthesesUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceWithinOtherParentheses(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceWithinOtherParenthesesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpaceWithinSquareBracketsUtf8, out IJsonDocument? _, out int _)) + { + SetSpaceWithinSquareBrackets(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpaceWithinSquareBracketsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpacesIgnoreAroundVariableDeclarationUtf8, out IJsonDocument? _, out int _)) + { + SetSpacesIgnoreAroundVariableDeclaration(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpacesIgnoreAroundVariableDeclarationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpacingAfterMethodDeclarationNameUtf8, out IJsonDocument? _, out int _)) + { + SetSpacingAfterMethodDeclarationName(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpacingAfterMethodDeclarationNameEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpacingAroundBinaryOperatorUtf8, out IJsonDocument? _, out int _)) + { + SetSpacingAroundBinaryOperator(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.SpacingAroundBinaryOperatorEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TabSizeUtf8, out IJsonDocument? _, out int _)) + { + SetTabSize(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.TabSizeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseTabsUtf8, out IJsonDocument? _, out int _)) + { + SetUseTabs(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.UseTabsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WrappingKeepStatementsOnSingleLineUtf8, out IJsonDocument? _, out int _)) + { + SetWrappingKeepStatementsOnSingleLine(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.WrappingKeepStatementsOnSingleLineEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WrappingPreserveSingleLineUtf8, out IJsonDocument? _, out int _)) + { + SetWrappingPreserveSingleLine(Corvus.OmnisharpBenchmark.Current.OmnisharpSchema.UsedToControlCFormatting.WrappingPreserveSingleLineEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineEntity.cs index 2039af87ce4..880d8595bb6 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public NewLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForCatchEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForCatchEntity.cs index c8af55b5ef7..c8fb11e5d48 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForCatchEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForCatchEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLineForCatchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForClausesInQueryEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForClausesInQueryEntity.cs index 4bffabc31b2..34338204fc7 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForClausesInQueryEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForClausesInQueryEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLineForClausesInQueryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForElseEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForElseEntity.cs index acb34ac4cdd..e95c78f6cd4 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForElseEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLineForElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForFinallyEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForFinallyEntity.cs index c1677cde340..b53b2232ac9 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForFinallyEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForFinallyEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLineForFinallyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInAnonymousTypesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInAnonymousTypesEntity.cs index 595e21f6d0f..e4ed17c6978 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInAnonymousTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInAnonymousTypesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLineForMembersInAnonymousTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInObjectInitEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInObjectInitEntity.cs index 98ce1444927..2fea8ea4c9c 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInObjectInitEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLineForMembersInObjectInitEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLineForMembersInObjectInitEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAccessorsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAccessorsEntity.cs index e0542f35f6c..2bcc15f6049 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAccessorsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAccessorsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInAccessorsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousMethodsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousMethodsEntity.cs index 36db9b87eaf..197c9aa5298 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousMethodsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousMethodsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInAnonymousMethodsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousTypesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousTypesEntity.cs index 89088e06155..ecdbdead3e4 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInAnonymousTypesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInAnonymousTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInControlBlocksEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInControlBlocksEntity.cs index 879c0e2e7c0..4ad5fb40ea5 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInControlBlocksEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInControlBlocksEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInControlBlocksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInLambdaExpressionBodyEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInLambdaExpressionBodyEntity.cs index 9c17158d7ff..0ca4b0fc5f4 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInLambdaExpressionBodyEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInLambdaExpressionBodyEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInLambdaExpressionBodyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInMethodsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInMethodsEntity.cs index e9c97ed29bd..517f25f7e78 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInMethodsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInMethodsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInMethodsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInObjectCollectionArrayInitializersEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInObjectCollectionArrayInitializersEntity.cs index 557f259e43d..8c9d06fff9f 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInObjectCollectionArrayInitializersEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInObjectCollectionArrayInitializersEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInObjectCollectionArrayInitializersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInPropertiesEntity.cs index 83c336619f4..4eee7d500b5 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInPropertiesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInTypesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInTypesEntity.cs index a42df35493f..6ceda36c741 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.NewLinesForBracesInTypesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public NewLinesForBracesInTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCastEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCastEntity.cs index e3d1eed1989..4d1cb48960b 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCastEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCastEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceAfterCastEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterColonInBaseTypeDeclarationEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterColonInBaseTypeDeclarationEntity.cs index c80706dda26..2ff601dd7f7 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterColonInBaseTypeDeclarationEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterColonInBaseTypeDeclarationEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceAfterColonInBaseTypeDeclarationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCommaEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCommaEntity.cs index bda0a520d1d..3afb02a69c5 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCommaEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterCommaEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceAfterCommaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterControlFlowStatementKeywordEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterControlFlowStatementKeywordEntity.cs index a7362f6275c..7e5a9d94a77 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterControlFlowStatementKeywordEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterControlFlowStatementKeywordEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceAfterControlFlowStatementKeywordEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterDotEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterDotEntity.cs index 874c7f6cf38..97cf6ebc105 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterDotEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterDotEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceAfterDotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterMethodCallNameEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterMethodCallNameEntity.cs index cea16945abe..15810a1dabc 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterMethodCallNameEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterMethodCallNameEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceAfterMethodCallNameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterSemicolonsInForStatementEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterSemicolonsInForStatementEntity.cs index ac63d19a31d..29a61db2e17 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterSemicolonsInForStatementEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceAfterSemicolonsInForStatementEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceAfterSemicolonsInForStatementEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeColonInBaseTypeDeclarationEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeColonInBaseTypeDeclarationEntity.cs index 150378bda77..40fb166ee44 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeColonInBaseTypeDeclarationEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeColonInBaseTypeDeclarationEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBeforeColonInBaseTypeDeclarationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeCommaEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeCommaEntity.cs index bde9063bf03..bca4900fde0 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeCommaEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeCommaEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBeforeCommaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeDotEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeDotEntity.cs index b6647938fbd..35714ed35b2 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeDotEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeDotEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBeforeDotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeOpenSquareBracketEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeOpenSquareBracketEntity.cs index a731c36e9e0..b1545df7514 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeOpenSquareBracketEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeOpenSquareBracketEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBeforeOpenSquareBracketEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeSemicolonsInForStatementEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeSemicolonsInForStatementEntity.cs index 66819cafa8c..507e74c0953 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeSemicolonsInForStatementEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBeforeSemicolonsInForStatementEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBeforeSemicolonsInForStatementEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodCallParenthesesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodCallParenthesesEntity.cs index ce119b77c83..32f9f4d4a6f 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodCallParenthesesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodCallParenthesesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBetweenEmptyMethodCallParenthesesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodDeclarationParenthesesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodDeclarationParenthesesEntity.cs index f9583ae166c..c75c946cf83 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodDeclarationParenthesesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptyMethodDeclarationParenthesesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBetweenEmptyMethodDeclarationParenthesesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptySquareBracketsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptySquareBracketsEntity.cs index 32381d5eab2..bdbf5a0f1c4 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptySquareBracketsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceBetweenEmptySquareBracketsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceBetweenEmptySquareBracketsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinCastParenthesesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinCastParenthesesEntity.cs index f0c89d163a2..6866d1ec0bc 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinCastParenthesesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinCastParenthesesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceWithinCastParenthesesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinExpressionParenthesesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinExpressionParenthesesEntity.cs index 8b28e7a21fe..f98c1adef3e 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinExpressionParenthesesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinExpressionParenthesesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceWithinExpressionParenthesesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodCallParenthesesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodCallParenthesesEntity.cs index f6489fee8a3..fc6fd792664 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodCallParenthesesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodCallParenthesesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceWithinMethodCallParenthesesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodDeclarationParenthesisEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodDeclarationParenthesisEntity.cs index 5ec7810dce0..61a0d8fdc6d 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodDeclarationParenthesisEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinMethodDeclarationParenthesisEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceWithinMethodDeclarationParenthesisEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinOtherParenthesesEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinOtherParenthesesEntity.cs index cf34b40274d..216933e28aa 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinOtherParenthesesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinOtherParenthesesEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceWithinOtherParenthesesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinSquareBracketsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinSquareBracketsEntity.cs index 55567ec1abd..906bd0abab2 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinSquareBracketsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpaceWithinSquareBracketsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpaceWithinSquareBracketsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacesIgnoreAroundVariableDeclarationEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacesIgnoreAroundVariableDeclarationEntity.cs index 242634f47ca..f468ca40df6 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacesIgnoreAroundVariableDeclarationEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacesIgnoreAroundVariableDeclarationEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpacesIgnoreAroundVariableDeclarationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAfterMethodDeclarationNameEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAfterMethodDeclarationNameEntity.cs index 2f58fd9d792..84ec036d907 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAfterMethodDeclarationNameEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAfterMethodDeclarationNameEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpacingAfterMethodDeclarationNameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAroundBinaryOperatorEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAroundBinaryOperatorEntity.cs index d3540fcb33c..26811d4eacf 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAroundBinaryOperatorEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.SpacingAroundBinaryOperatorEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SpacingAroundBinaryOperatorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.TabSizeEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.TabSizeEntity.cs index 3720f5b8c73..fa788ee9859 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.TabSizeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.TabSizeEntity.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public TabSizeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.UseTabsEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.UseTabsEntity.cs index ac800cab47d..6dcb326aca1 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.UseTabsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.UseTabsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public UseTabsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingKeepStatementsOnSingleLineEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingKeepStatementsOnSingleLineEntity.cs index 6fb4f72870f..71cbdbc143c 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingKeepStatementsOnSingleLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingKeepStatementsOnSingleLineEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public WrappingKeepStatementsOnSingleLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingPreserveSingleLineEntity.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingPreserveSingleLineEntity.cs index a101a9049f8..dacc60cf9eb 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingPreserveSingleLineEntity.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.WrappingPreserveSingleLineEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public WrappingPreserveSingleLineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.cs index 15bf85fa7f9..1e003f1f5ee 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.UsedToControlCFormatting.cs @@ -1176,6 +1176,12 @@ private void CheckValidInstance() public UsedToControlCFormatting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.cs b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.cs index 08d4e61a599..7a4825773c4 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.cs +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/OmnisharpSchema.cs @@ -510,6 +510,12 @@ private void CheckValidInstance() public OmnisharpSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/corvusjson-jsonschema.lock index 8921c8a7bf5..35f0971ac2c 100644 --- a/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.OmnisharpBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:40.2819495\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:25.1192511\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonBoolean.cs index e3993cfbd2d..bdae4bd3b5f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonEmail.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonEmail.cs index 52da9cc2cdd..6114adf56e3 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonEmail.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonEmail.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonEmail Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonMediaRange.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonMediaRange.cs index b31e0cb47ab..830da8ad770 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonMediaRange.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonMediaRange.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonMediaRange Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonString.cs index e60dc52638d..282fe4e94e4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUri.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUri.cs index f8cf1c78c65..d39a5bdcd33 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUri.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUri.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public JsonUri Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUriReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUriReference.cs index 71aff10aedf..97134e5dbc8 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUriReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/JsonUriReference.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public JsonUriReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Callbacks.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Callbacks.cs index 59573fa8b8e..6ca23387f47 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Callbacks.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Callbacks.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public Callbacks Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.Mutable.cs index c18af4c5406..ae812ee123c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.Mutable.cs @@ -395,6 +395,31 @@ public bool RemoveSummary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.Mutable.cs index 820c64e8288..e6ed6f7064a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.cs index c8dc8010777..003f30b8637 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.cs index fd5c605e122..0103f849de5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.CallbacksOrReference.cs @@ -387,6 +387,12 @@ private void CheckValidInstance() public CallbacksOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.CallbacksEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.CallbacksEntity.cs index 5bea70dec5b..a4e33afd951 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.CallbacksEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.CallbacksEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public CallbacksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ExamplesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ExamplesEntity.cs index 3e3731e06b0..4a3479dddd5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ExamplesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ExamplesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public ExamplesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.HeadersEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.HeadersEntity.cs index 2f97e806942..1085d643f37 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.HeadersEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.HeadersEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public HeadersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.LinksEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.LinksEntity.cs index 1082ed8480e..a32b369ffa1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.LinksEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.LinksEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public LinksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.Mutable.cs index fe826c91a69..65a0984651a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.Mutable.cs @@ -1155,6 +1155,31 @@ public bool RemoveSecuritySchemes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ParametersEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ParametersEntity.cs index 1c435592976..6006351761c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ParametersEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ParametersEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public ParametersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.PathItemsEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.PathItemsEntity.cs index de562158fc9..3680a570f26 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.PathItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.PathItemsEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public PathItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.RequestBodiesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.RequestBodiesEntity.cs index 4c015b59c81..c3d6f5df655 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.RequestBodiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.RequestBodiesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public RequestBodiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ResponsesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ResponsesEntity.cs index 15db1e38bb3..c0954b30e21 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ResponsesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.ResponsesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public ResponsesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasEntity.cs index 57c2c91d9d5..a203a7b133b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public SchemasEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.PropertyNamesEntity.cs index a08c9752eaa..28e80e6e7ff 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.PropertyNamesEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.cs index 30c4df8082b..3d19d951fe0 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public SchemasResponsesParametersExamplesRequestBodiesHeadersSecuritySchemesLinksCallbacksPathItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SecuritySchemesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SecuritySchemesEntity.cs index 4f7c5472232..d2eb8aa4152 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SecuritySchemesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.SecuritySchemesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public SecuritySchemesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.cs index 650ebede07f..a96d9c57c74 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Components.cs @@ -570,6 +570,12 @@ private void CheckValidInstance() public Components Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.Mutable.cs index 69f45480527..e8d1b829166 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.Mutable.cs @@ -361,6 +361,31 @@ public bool RemoveUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.cs index 49714894610..22930ae5ede 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Contact.cs @@ -353,6 +353,12 @@ private void CheckValidInstance() public Contact Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.PropertyNamesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.PropertyNamesEntity.cs index 9ce45da47d2..d03b176123e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.PropertyNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.PropertyNamesEntity.cs @@ -457,6 +457,12 @@ private void CheckValidInstance() public PropertyNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.cs index 25924554d9a..4903dd016e5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Content.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public Content Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ContentEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ContentEntity.cs index 5c6673a4e21..a87324571d1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ContentEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ContentEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public ContentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.AllowReservedEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.AllowReservedEntity.cs index 06f8567060b..8144ef301e8 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.AllowReservedEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.AllowReservedEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AllowReservedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.HeadersEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.HeadersEntity.cs index c9fc5e6226e..aa376d45eba 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.HeadersEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.HeadersEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public HeadersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.Mutable.cs index d9b97fb8eb9..d4d0408d9d5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.Mutable.cs @@ -537,6 +537,41 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowReservedUtf8, out IJsonDocument? _, out int _)) + { + SetAllowReserved(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Encoding.AllowReservedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Encoding.StyleEntity.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.StyleEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.StyleEntity.cs index 0eaa33c16f2..98c1936f503 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.StyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.StyleEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public StyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.cs index e0926c86966..b56840b0429 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Encoding.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public Encoding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.EncodingEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.EncodingEntity.cs index 7f21f4114ff..4ee542a535c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.EncodingEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.EncodingEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public EncodingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.Mutable.cs index 32675a39bcc..76337f70eba 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.Mutable.cs @@ -458,6 +458,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.Mutable.cs index af4d111014a..bd157872a4b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.Mutable.cs @@ -386,6 +386,31 @@ public void SetValue(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.cs index 33fc9ffa7f2..cb430846416 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.RequiredExternalValueAndValue.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredExternalValueAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.cs index 98a6eb74e9d..dc9706fcfc4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Example.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public Example Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.Mutable.cs index 1c5b584b9ac..0f11af34982 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.Mutable.cs @@ -553,6 +553,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.Mutable.cs index 69050de06a0..2763ab504c9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.cs index ad843a42960..6ba59024107 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.cs index abaf0b10a48..fd0f779b9e7 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExampleOrReference.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public ExampleOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.ExamplesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.ExamplesEntity.cs index d0de1243aa1..84c7fb8ddc3 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.ExamplesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.ExamplesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public ExamplesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.Mutable.cs index 8819cf6f988..f8750fe1440 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.Mutable.cs @@ -406,6 +406,31 @@ public bool RemoveExamplesValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.cs index b582d94f433..acc15b5a6e4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Examples.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public Examples Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.Mutable.cs index 77716ef6f8a..06d3e4c7879 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.Mutable.cs @@ -291,6 +291,31 @@ public void SetUrl(scoped in Corvus.OpenapiBenchmark.Current.JsonUri.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.cs index ee33cd1d2b4..9553cf0e590 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ExternalDocumentation.cs @@ -342,6 +342,12 @@ private void CheckValidInstance() public ExternalDocumentation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.ContentEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.ContentEntity.cs index 5162502db65..ef5e13c4b73 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.ContentEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.ContentEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public ContentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.DeprecatedEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.DeprecatedEntity.cs index e027085d23a..8aff8e9b5ed 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.DeprecatedEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.DeprecatedEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public DeprecatedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.Mutable.cs index c29a2890353..ec4ba67383f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.Mutable.cs @@ -907,6 +907,51 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeprecatedUtf8, out IJsonDocument? _, out int _)) + { + SetDeprecated(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.DeprecatedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExplodeUtf8, out IJsonDocument? _, out int _)) + { + SetExplode(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.WithStyleSimple.ExplodeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequiredUtf8, out IJsonDocument? _, out int _)) + { + SetRequired(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.RequiredEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.WithStyleSimple.StyleEntity.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.Mutable.cs index e72dc7735ca..ccd7e133c53 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.Mutable.cs @@ -300,6 +300,31 @@ public void SetContent(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.cs index dd5b8a74d9d..c94d75ddd7b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredContent.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredContent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredEntity.cs index 0c9f67bedc1..22824184c2a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RequiredEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.Mutable.cs index 15f361ad0b1..90e247c1065 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.Mutable.cs @@ -300,6 +300,31 @@ public void SetSchema(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.cs index 1ed311ddb67..3338f42163a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.RequiredSchema.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.ExplodeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.ExplodeEntity.cs index db759d56fb2..a0a8cbd6d45 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.ExplodeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.ExplodeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public ExplodeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.Mutable.cs index c39a8796154..2dc5d5c1946 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.Mutable.cs @@ -548,6 +548,41 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExplodeUtf8, out IJsonDocument? _, out int _)) + { + SetExplode(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.WithStyleSimple.ExplodeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.WithStyleSimple.StyleEntity.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.StyleEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.StyleEntity.cs index 26235beebab..5f4d3fd2a92 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.StyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.StyleEntity.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public StyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.cs index 02722f8f4d1..242a8739ab4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.WithStyleSimple.cs @@ -423,6 +423,12 @@ private void CheckValidInstance() public WithStyleSimple Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.cs index 50eeafddfed..0cb11dc76b1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Header.cs @@ -503,6 +503,12 @@ private void CheckValidInstance() public Header Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement
(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.Mutable.cs index 538931952d2..1399a52f174 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.Mutable.cs @@ -1027,6 +1027,51 @@ public bool RemoveSummary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeprecatedUtf8, out IJsonDocument? _, out int _)) + { + SetDeprecated(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.DeprecatedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExplodeUtf8, out IJsonDocument? _, out int _)) + { + SetExplode(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.WithStyleSimple.ExplodeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequiredUtf8, out IJsonDocument? _, out int _)) + { + SetRequired(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.RequiredEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Header.WithStyleSimple.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.Mutable.cs index c3ff26ee283..706f1e808fa 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.cs index 104ef82b4fc..762b861b0fb 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.cs index e9555bcd0b1..9a81c9552cc 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeaderOrReference.cs @@ -515,6 +515,12 @@ private void CheckValidInstance() public HeaderOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeadersEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeadersEntity.cs index aa974dc8d12..8c775fd72b9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeadersEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.HeadersEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public HeadersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.Mutable.cs index 30e27ec2725..8498d2b2563 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.Mutable.cs @@ -659,6 +659,43 @@ public void SetVersion(scoped in Corvus.OpenapiBenchmark.Current.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContactValueUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Contact.Mutable __corvusContactValue)) + { + __corvusContactValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LicenseValueUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.License.Mutable __corvusLicenseValue)) + { + __corvusLicenseValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.cs index 19da2ca7fb0..a1733c2953f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Info.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public Info Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.JsonSchemaDialectEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.JsonSchemaDialectEntity.cs index a50c009f74a..45e0ae3cc86 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.JsonSchemaDialectEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.JsonSchemaDialectEntity.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public JsonSchemaDialectEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.Mutable.cs index 2b088debc52..5ddca1bfff1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.Mutable.cs @@ -302,6 +302,31 @@ public void SetUrl(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.cs index 77a2f1fa024..63545c24768 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.RequiredUrl.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.cs index 233532409b4..e17aed0c64b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.IdentifierEntity.cs @@ -457,6 +457,12 @@ private void CheckValidInstance() public IdentifierEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.Mutable.cs index b0f63d7e9cf..3ec7242cec5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.Mutable.cs @@ -352,6 +352,31 @@ public bool RemoveUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.cs index 4e902ec1ef6..7a7a05405b1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.License.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public License Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.Mutable.cs index 6430ccdb6a3..12173795b73 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.Mutable.cs @@ -688,6 +688,37 @@ public bool RemoveRequestBody() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BodyUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Server.Mutable __corvusBody)) + { + __corvusBody.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.Mutable.cs index 40151c25e8f..1e23a7b58a3 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.Mutable.cs @@ -300,6 +300,31 @@ public void SetOperationId(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.cs index 928ec28d07d..046adca5e0e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationId.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredOperationId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.Mutable.cs index 63fa76b8bd8..adf4029bcb8 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetOperationRef(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.cs index 0e662bb8e24..325f0d4e6b9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.RequiredOperationRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredOperationRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.cs index 58b77601639..2f1d41242d1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Link.cs @@ -455,6 +455,12 @@ private void CheckValidInstance() public Link Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.Mutable.cs index 33f9d41d258..4543324b407 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.Mutable.cs @@ -808,6 +808,37 @@ public bool RemoveSummary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BodyUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Server.Mutable __corvusBody)) + { + __corvusBody.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.Mutable.cs index 2000a62f8cb..56b13d22982 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.cs index 320a2a82774..337976c4ec1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.cs index e21bad2a6af..2b0863b1c5c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.LinkOrReference.cs @@ -467,6 +467,12 @@ private void CheckValidInstance() public LinkOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MapOfStrings.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MapOfStrings.cs index f03009f1bbc..72eede8fe42 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MapOfStrings.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MapOfStrings.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public MapOfStrings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.EncodingEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.EncodingEntity.cs index 7db74f9a3a2..48359388927 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.EncodingEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.EncodingEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public EncodingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.Mutable.cs index cccdb98961f..8e9c1710a4a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.Mutable.cs @@ -584,6 +584,31 @@ public bool RemoveSchemaValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.cs index 3739e793775..a4a15c188bf 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.MediaType.cs @@ -387,6 +387,12 @@ private void CheckValidInstance() public MediaType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Mutable.cs index d6f76ef24bd..9dee5255b23 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Mutable.cs @@ -1107,6 +1107,59 @@ public bool RemoveWebhooks() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsonSchemaDialectUtf8, out IJsonDocument? _, out int _)) + { + SetJsonSchemaDialect(Corvus.OpenapiBenchmark.Current.OpenapiSchema.JsonSchemaDialectEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServersUtf8, out IJsonDocument? _, out int _)) + { + SetServers(Corvus.OpenapiBenchmark.Current.OpenapiSchema.ServerArray.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentsValueUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Components.Mutable __corvusComponentsValue)) + { + __corvusComponentsValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExternalDocsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.ExternalDocumentation.Mutable __corvusExternalDocs)) + { + __corvusExternalDocs.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InfoValueUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Info.Mutable __corvusInfoValue)) + { + __corvusInfoValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.Mutable.cs index 7751c250458..cbeb9e6db7b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.Mutable.cs @@ -566,6 +566,55 @@ public bool RemovePassword() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthorizationCodeUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.Mutable __corvusAuthorizationCode)) + { + __corvusAuthorizationCode.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ClientCredentialsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.Mutable __corvusClientCredentials)) + { + __corvusClientCredentials.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImplicitUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.Mutable __corvusImplicit)) + { + __corvusImplicit.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PasswordUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.Mutable __corvusPassword)) + { + __corvusPassword.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.Mutable.cs index 3c070d7478b..f52d45a6f6c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.Mutable.cs @@ -379,6 +379,31 @@ public void SetTokenUrl(scoped in Corvus.OpenapiBenchmark.Current.JsonUri.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.cs index 0bf13cf49f4..fd00c3eec04 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.OauthFlowsRequiredScopesAndTokenUrl.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public OauthFlowsRequiredScopesAndTokenUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.Mutable.cs index 6682bb0b47d..16d2c60fbc4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.Mutable.cs @@ -379,6 +379,31 @@ public void SetScopes(in Corvus.OpenapiBenchmark.Current.OpenapiSchema _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.cs index 9f3ce77fcd4..be85661c8f4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopes.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public RequiredAuthorizationUrlAndScopes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.Mutable.cs index ba7c215617b..58c7d428bdb 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.Mutable.cs @@ -431,6 +431,31 @@ public void SetTokenUrl(scoped in Corvus.OpenapiBenchmark.Current.JsonUri.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.cs index cd736c39b7f..e1dfb239cca 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredAuthorizationUrlAndScopesAndTokenUrl.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public RequiredAuthorizationUrlAndScopesAndTokenUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.Mutable.cs index 38c05f75dde..cf8331cab6f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.Mutable.cs @@ -379,6 +379,31 @@ public void SetTokenUrl(scoped in Corvus.OpenapiBenchmark.Current.JsonUri.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.cs index efd5bbb421d..02d9dcce3f3 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.RequiredScopesAndTokenUrl.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public RequiredScopesAndTokenUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.cs index beeeb6df74f..5bad85bfc4a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OauthFlows.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public OauthFlows Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiEntity.cs index fb2b694c899..2739e3b6685 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public OpenapiEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaContentEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaContentEntity.cs index a75aa631a7c..45b80acccad 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaContentEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaContentEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public OpenapiSchemaContentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaHeadersEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaHeadersEntity.cs index 78aca2ad0e5..b6edf7375b9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaHeadersEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaHeadersEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public OpenapiSchemaHeadersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaParametArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaParametArray.cs index 8d0e304c13a..7d15bc22925 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaParametArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.OpenapiSchemaParametArray.cs @@ -21,11 +21,13 @@ public readonly partial struct OpenapiSchema public readonly partial struct OpenapiSchemaParametArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public OpenapiSchemaParametArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.CallbacksEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.CallbacksEntity.cs index 08f264885c0..c6d45e487af 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.CallbacksEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.CallbacksEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public CallbacksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.DeprecatedEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.DeprecatedEntity.cs index 6c6732177bb..dec1aea6e64 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.DeprecatedEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.DeprecatedEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public DeprecatedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.JsonStringArray.cs index 33460f86289..e468627f153 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Operation public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.Mutable.cs index 3292737f373..b0082e47e20 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.Mutable.cs @@ -1198,6 +1198,54 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeprecatedUtf8, out IJsonDocument? _, out int _)) + { + SetDeprecated(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.DeprecatedEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExternalDocsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.ExternalDocumentation.Mutable __corvusExternalDocs)) + { + __corvusExternalDocs.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequestBodyUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.RequestBodyOrReference.Mutable __corvusRequestBody)) + { + __corvusRequestBody.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResponsesValueUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Responses.Mutable __corvusResponsesValue)) + { + __corvusResponsesValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ParameterOrReferenceArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ParameterOrReferenceArray.cs index c9d3b60660c..1a0825f438a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ParameterOrReferenceArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ParameterOrReferenceArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Operation public readonly partial struct ParameterOrReferenceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ParameterOrReferenceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.SecurityRequirementArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.SecurityRequirementArray.cs index ee4920dbb58..42dd3ef4e2c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.SecurityRequirementArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.SecurityRequirementArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Operation public readonly partial struct SecurityRequirementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public SecurityRequirementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ServerArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ServerArray.cs index 219aa51edc7..41b8965b713 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ServerArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.ServerArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Operation public readonly partial struct ServerArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ServerArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.cs index 444e565a6f5..a9a939ab529 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Operation.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public Operation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ContentEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ContentEntity.cs index 06194eb7699..0ebd1426fc7 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ContentEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ContentEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public ContentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.DeprecatedEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.DeprecatedEntity.cs index 4438af0ce6a..e8018c13ab3 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.DeprecatedEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.DeprecatedEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public DeprecatedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.InEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.InEntity.cs index eaec701756a..796bc62723c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.InEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.InEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public InEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.Mutable.cs index 6db5c23aa8f..965d0640355 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.Mutable.cs @@ -1133,6 +1133,51 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowEmptyValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowEmptyValue(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.ThenEntity.AllowEmptyValueEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowReservedUtf8, out IJsonDocument? _, out int _)) + { + SetAllowReserved(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeprecatedUtf8, out IJsonDocument? _, out int _)) + { + SetDeprecated(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.DeprecatedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequiredUtf8, out IJsonDocument? _, out int _)) + { + SetRequired(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.RequiredEntity.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.Mutable.cs index 9479a0b95d3..6992dbb8f2b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.Mutable.cs @@ -300,6 +300,31 @@ public void SetContent(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.cs index ad336892b5f..f22c4df92fa 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredContent.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredContent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredEntity.cs index 2cb755541e7..d7a7eb7662a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RequiredEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.InEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.InEntity.cs index 139c39822b2..e5365162bb1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.InEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.InEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public InEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.Mutable.cs index 348376fd672..cd43ea8cde5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.Mutable.cs @@ -266,6 +266,31 @@ public void SetIn(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parame _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.cs index 5adc40ee024..567c4f48846 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredIn.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredIn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.Mutable.cs index b89410cdb95..429b0411815 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.Mutable.cs @@ -300,6 +300,31 @@ public void SetSchema(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.cs index 35f9adbac87..10e66936358 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.RequiredSchema.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.Mutable.cs index 212d5332910..513057fed7b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.Mutable.cs @@ -760,6 +760,36 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowReservedUtf8, out IJsonDocument? _, out int _)) + { + SetAllowReserved(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.Mutable.cs index 6738f774c45..101a50af3c5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.Mutable.cs @@ -277,6 +277,36 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.InEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.InEntity.cs index 4d6b43c0314..c9c42452589 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.InEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.InEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public InEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.Mutable.cs index d122adf0788..b4feb07512f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.Mutable.cs @@ -270,6 +270,31 @@ public void SetIn(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parame _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.cs index d73eb2f01e7..47c2760b502 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.RequiredIn.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public RequiredIn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.Mutable.cs index 4853f5c403a..a39fdb999f2 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.Mutable.cs @@ -279,6 +279,36 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.StyleEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.StyleEntity.cs index a71f3a897fa..9c8226ef6db 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.StyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.StyleEntity.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public StyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.cs index daca3596b8d..90827a9d7df 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.WithStyleForm.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public WithStyleForm Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.cs index 43721534f49..022f0563590 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForCookieEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public StylesForCookieEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.Mutable.cs index b3cd7574df3..4d85ad23e82 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.Mutable.cs @@ -277,6 +277,36 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.InEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.InEntity.cs index cd651bf6f44..fb5d2545891 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.InEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.InEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public InEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.Mutable.cs index 48adf86ada9..b07db7234f4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.Mutable.cs @@ -270,6 +270,31 @@ public void SetIn(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parame _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.cs index 3c81abcddd4..068e8190d15 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.RequiredIn.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public RequiredIn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.Mutable.cs index ba5eff06cc2..b238176eac9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.Mutable.cs @@ -279,6 +279,36 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.StyleEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.StyleEntity.cs index f292e705ab7..74b52ec303e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.StyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.StyleEntity.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public StyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.cs index d0023994999..c8c2b9cae99 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.WithStyleSimple.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public WithStyleSimple Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.cs index 0eb14339a11..bb7f4c6aa63 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForHeaderEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public StylesForHeaderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.Mutable.cs index fafd07c32a4..22b17d67e14 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.Mutable.cs @@ -338,6 +338,36 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.InEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.InEntity.cs index 398d0a4596b..caf2c894872 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.InEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.InEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public InEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.Mutable.cs index f7541cc5999..25324839306 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.Mutable.cs @@ -270,6 +270,31 @@ public void SetIn(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parame _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.cs index 407bfbe3218..0f5308f9c61 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredIn.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public RequiredIn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.Mutable.cs index a1611e72e60..bde5f115d9d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.Mutable.cs @@ -331,6 +331,36 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.RequiredEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.RequiredEntity.cs index 8789337ba9f..df5a70d7e72 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.RequiredEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.RequiredEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public RequiredEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.StyleEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.StyleEntity.cs index 07af2139363..40a68a47979 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.StyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.StyleEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public StyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.cs index bdf2f069905..6af76b3557b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.RequiredRequired.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public RequiredRequired Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.cs index eac431f5c15..d9ce2d28d4e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForPathEntity.cs @@ -375,6 +375,12 @@ private void CheckValidInstance() public StylesForPathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.Mutable.cs index 613cd271007..26eccb0748a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.Mutable.cs @@ -338,6 +338,41 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowReservedUtf8, out IJsonDocument? _, out int _)) + { + SetAllowReserved(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.InEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.InEntity.cs index 6539042603d..95f0182635d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.InEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.InEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public InEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.Mutable.cs index ab70830f4ab..467decb15bd 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.Mutable.cs @@ -270,6 +270,31 @@ public void SetIn(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parame _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.cs index 6faf4d71844..11bdbbc8b5f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.RequiredIn.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public RequiredIn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.cs index 77e722aca9b..ae256f5d7d3 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public AllowReservedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.Mutable.cs index 1125a49be16..2a6ddaf1e95 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.Mutable.cs @@ -340,6 +340,41 @@ public bool RemoveStyle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowReservedUtf8, out IJsonDocument? _, out int _)) + { + SetAllowReserved(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.StyleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.StyleEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.StyleEntity.cs index e6ae8fcec1c..7871a774cf4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.StyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.StyleEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public StyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.cs index e6377d7b7be..e927652764e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.cs @@ -377,6 +377,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.cs index d8261521b80..a775dbcac26 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.cs @@ -375,6 +375,12 @@ private void CheckValidInstance() public StylesForQueryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.cs index 2ac828c69c4..1dd5d8208a0 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.SchemaEntity.cs @@ -545,6 +545,12 @@ private void CheckValidInstance() public SchemaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.AllowEmptyValueEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.AllowEmptyValueEntity.cs index 2469183f75c..265a9e7d95d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.AllowEmptyValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.AllowEmptyValueEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public AllowEmptyValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.Mutable.cs index bac173eba88..161708322eb 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.Mutable.cs @@ -275,6 +275,36 @@ public bool RemoveAllowEmptyValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowEmptyValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowEmptyValue(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.ThenEntity.AllowEmptyValueEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.cs index 1f8a87fb855..0f28f2d8026 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.ThenEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.cs index 08cfbaa60d3..ac69ebf4d2b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Parameter.cs @@ -577,6 +577,12 @@ private void CheckValidInstance() public Parameter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.Mutable.cs index 369039c89f9..1820716b73d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.Mutable.cs @@ -1271,6 +1271,51 @@ public bool RemoveSummary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowEmptyValueUtf8, out IJsonDocument? _, out int _)) + { + SetAllowEmptyValue(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.ThenEntity.AllowEmptyValueEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowReservedUtf8, out IJsonDocument? _, out int _)) + { + SetAllowReserved(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.SchemaEntity.StylesForQueryEntity.ThenEntity.AllowReservedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeprecatedUtf8, out IJsonDocument? _, out int _)) + { + SetDeprecated(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.DeprecatedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequiredUtf8, out IJsonDocument? _, out int _)) + { + SetRequired(Corvus.OpenapiBenchmark.Current.OpenapiSchema.Parameter.RequiredEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.Mutable.cs index 2fed5f13801..24778a5a361 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.cs index ac1f83e0a8a..dfa32829cab 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.cs index 4b88899bec0..9aa223bf453 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReference.cs @@ -579,6 +579,12 @@ private void CheckValidInstance() public ParameterOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReferenceArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReferenceArray.cs index 38d4c6986f2..c87180e2833 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReferenceArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ParameterOrReferenceArray.cs @@ -21,11 +21,13 @@ public readonly partial struct OpenapiSchema public readonly partial struct ParameterOrReferenceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public ParameterOrReferenceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.Mutable.cs index 82e309bdc2e..df9ebb43cb6 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.Mutable.cs @@ -1270,6 +1270,79 @@ public bool RemoveTrace() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeleteUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusDelete)) + { + __corvusDelete.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GetUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusGet)) + { + __corvusGet.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeadUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusHead)) + { + __corvusHead.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusOptions)) + { + __corvusOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PatchUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusPatch)) + { + __corvusPatch.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PostUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusPost)) + { + __corvusPost.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PutUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusPut)) + { + __corvusPut.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TraceUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusTrace)) + { + __corvusTrace.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ParameterOrReferenceArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ParameterOrReferenceArray.cs index 64f44d49811..c661cda0942 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ParameterOrReferenceArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ParameterOrReferenceArray.cs @@ -23,11 +23,13 @@ public readonly partial struct PathItem public readonly partial struct ParameterOrReferenceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ParameterOrReferenceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ServerArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ServerArray.cs index 64ac7e4a14a..0766da3aeac 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ServerArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.ServerArray.cs @@ -23,11 +23,13 @@ public readonly partial struct PathItem public readonly partial struct ServerArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ServerArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.cs index 0ec35b48298..650aea00b81 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItem.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public PathItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.Mutable.cs index 57604677119..1da7b754ab8 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.Mutable.cs @@ -1365,6 +1365,79 @@ public bool RemoveTrace() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeleteUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusDelete)) + { + __corvusDelete.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GetUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusGet)) + { + __corvusGet.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeadUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusHead)) + { + __corvusHead.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusOptions)) + { + __corvusOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PatchUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusPatch)) + { + __corvusPatch.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PostUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusPost)) + { + __corvusPost.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PutUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusPut)) + { + __corvusPut.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TraceUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.Operation.Mutable __corvusTrace)) + { + __corvusTrace.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.Mutable.cs index bc3c5385d98..77470ca0139 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.cs index 651d621af04..20a00014b9e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.cs index d83c2275652..6241ddcadcb 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.PathItemOrReference.cs @@ -547,6 +547,12 @@ private void CheckValidInstance() public PathItemOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Paths.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Paths.cs index c91f438f335..f29134a3c8a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Paths.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Paths.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public Paths Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.Mutable.cs index 479418e1dc5..4cb118e91ed 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.Mutable.cs @@ -395,6 +395,31 @@ public bool RemoveSummary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.cs index 6df1cfd6278..793ee49ae94 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Reference.cs @@ -387,6 +387,12 @@ private void CheckValidInstance() public Reference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.Mutable.cs index f5e1119780e..35afc129bb0 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.Mutable.cs @@ -386,6 +386,36 @@ public bool RemoveRequired() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequiredUtf8, out IJsonDocument? _, out int _)) + { + SetRequired(Corvus.OpenapiBenchmark.Current.OpenapiSchema.RequestBody.RequiredEntity.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.RequiredEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.RequiredEntity.cs index 16a5307e982..d338e7157e6 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.RequiredEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.RequiredEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RequiredEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.cs index 9278c936a97..54310ae39ac 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBody.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public RequestBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.Mutable.cs index 52261c96d24..b7a9bd7d670 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.Mutable.cs @@ -553,6 +553,36 @@ public bool RemoveSummary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequiredUtf8, out IJsonDocument? _, out int _)) + { + SetRequired(Corvus.OpenapiBenchmark.Current.OpenapiSchema.RequestBody.RequiredEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.Mutable.cs index f65e06b44bb..2373d13088c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.cs index 2e1ee0bbd43..4c402d9d0f1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.cs index 03d1daad69b..f44428734e2 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequestBodyOrReference.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public RequestBodyOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.Mutable.cs index 1377d734f2e..3c6ea3c107e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.Mutable.cs @@ -298,6 +298,31 @@ public void SetComponents(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.cs index a59ebd1a9cb..0957183b974 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredComponents.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public RequiredComponents Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.Mutable.cs index 18eef04c445..4bcdc333927 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.Mutable.cs @@ -298,6 +298,31 @@ public void SetPaths(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.cs index faabb4b18fd..b2898274792 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredPaths.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public RequiredPaths Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.Mutable.cs index 7915eeadeba..91488ae3595 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.Mutable.cs @@ -298,6 +298,31 @@ public void SetWebhooks(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.cs index 66640a9fd97..8277149b420 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.RequiredWebhooks.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public RequiredWebhooks Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.HeadersEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.HeadersEntity.cs index 0268ae5709d..95332767480 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.HeadersEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.HeadersEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public HeadersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.LinksEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.LinksEntity.cs index 188ce28e739..aaf16c565d2 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.LinksEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.LinksEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public LinksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.Mutable.cs index 0efdd9c3bc2..804a7d21e39 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.Mutable.cs @@ -521,6 +521,31 @@ public bool RemoveLinks() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.cs index 4806330563c..ebc6c5dd992 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Response.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public Response Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.Mutable.cs index 98fd5003f40..485c4e64c5b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.Mutable.cs @@ -686,6 +686,31 @@ public bool RemoveSummary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.Mutable.cs index ba07c341967..9c7d62fd6d1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.cs index 55fe04a2e0e..ba42145c8ce 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.cs index 1935de1153f..6c836faf114 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ResponseOrReference.cs @@ -435,6 +435,12 @@ private void CheckValidInstance() public ResponseOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.IfEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.IfEntity.cs index 4fea26e03a1..3c76ec3eea7 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.IfEntity.cs @@ -439,6 +439,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.Mutable.cs index f31efcf0a99..2aae0e9f39f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.Mutable.cs @@ -282,6 +282,37 @@ public bool RemoveDefault() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.ResponseOrReference.Mutable __corvusDefault)) + { + __corvusDefault.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.Mutable.cs index 4acef59b354..37539b3c274 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.Mutable.cs @@ -300,6 +300,31 @@ public void SetDefault(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.cs index b38de129932..5d0e59d666a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.RequiredDefault.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredDefault Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.cs index a3483fd211c..2a3f0eb1be8 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Responses.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public Responses Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Schema.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Schema.cs index 6494f895936..8cd91c12c11 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Schema.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Schema.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public Schema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.JsonStringArray.cs index de009f94b67..258dc3be4d6 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct SecurityRequirement public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.cs index c57aa27f6ba..6aedb65626a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirement.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public SecurityRequirement Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirementArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirementArray.cs index 767767253de..e433b72110c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirementArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityRequirementArray.cs @@ -21,11 +21,13 @@ public readonly partial struct OpenapiSchema public readonly partial struct SecurityRequirementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public SecurityRequirementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.Mutable.cs index e1151b2da78..81d3791bc82 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.Mutable.cs @@ -783,6 +783,37 @@ public void SetType(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Secu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FlowsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.Mutable __corvusFlows)) + { + __corvusFlows.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.Mutable.cs index 7ef12343dfa..6390006a254 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.Mutable.cs @@ -336,6 +336,31 @@ public bool RemoveName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.InEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.InEntity.cs index 10dcb632fdd..84a8cbe878f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.InEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.InEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public InEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.Mutable.cs index f643b7fe8dc..1f69b023a73 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.Mutable.cs @@ -320,6 +320,31 @@ public void SetName(scoped in Corvus.OpenapiBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.cs index 745dbbe5889..d8a9ac21c3c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredInAndName.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public RequiredInAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.Mutable.cs index 9c4b9b7566f..1d90ef6b472 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.Mutable.cs @@ -268,6 +268,31 @@ public void SetType(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Secu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.TypeEntity.cs index b6cd6631778..734113ddf4f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.cs index b2190efdeab..102efbae4fe 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.RequiredType.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.cs index d0e33f39918..db034ece204 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeApikeyEntity.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public TypeApikeyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeEntity.cs index de9b8bd92dd..b80f9cfb5be 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.Mutable.cs index 37e3b11c25a..9daef2b3d30 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveBearerFormat() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.Mutable.cs index a89c7765478..6bdd402159d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.Mutable.cs @@ -320,6 +320,31 @@ public void SetType(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Secu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.SchemeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.SchemeEntity.cs index 80f35f24a59..be01b390241 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.SchemeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.SchemeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SchemeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.TypeEntity.cs index da5fda63cca..fcaadfa40f9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.cs index 77a0d7ec75b..874fd8f3e8d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.RequiredSchemeAndType.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public RequiredSchemeAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.Mutable.cs index e507566ded7..c00b4b417dc 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveBearerFormat() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.cs index 8c3d77f453c..934484c97dc 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.ThenEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.cs index 226eed9fffa..dcf9ec96c26 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpBearerEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public TypeHttpBearerEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.Mutable.cs index 24186e5468a..b5d283e1e1f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveScheme() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.Mutable.cs index 0f088006026..39746c6221c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.Mutable.cs @@ -268,6 +268,31 @@ public void SetScheme(scoped in Corvus.OpenapiBenchmark.Current.JsonString.Sourc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.cs index 970d1ff86a3..93cfbec2436 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredScheme.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredScheme Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.Mutable.cs index 97369532b96..afb5dd881b7 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.Mutable.cs @@ -268,6 +268,31 @@ public void SetType(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Secu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.TypeEntity.cs index ae8c78b45a9..65193b846f5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.cs index 72b5653b744..58838b1eb2d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.RequiredType.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.cs index 6f856061c28..3182029173c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeHttpEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public TypeHttpEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.Mutable.cs index 355eb86422e..0a67e481a4c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.Mutable.cs @@ -311,6 +311,37 @@ public bool RemoveFlows() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FlowsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.Mutable __corvusFlows)) + { + __corvusFlows.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.Mutable.cs index 110b1e56481..c753fe90649 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.Mutable.cs @@ -302,6 +302,37 @@ public void SetFlows(in Corvus.OpenapiBenchmark.Current.OpenapiSchema. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FlowsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.Mutable __corvusFlows)) + { + __corvusFlows.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.cs index 65f9fe635aa..585e1993a44 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredFlows.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredFlows Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.Mutable.cs index 6a481384573..01a91c2f07a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.Mutable.cs @@ -268,6 +268,31 @@ public void SetType(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Secu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.TypeEntity.cs index 48b5531b5c1..f78e11a4fca 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.cs index 3a97c1f522a..9602ac8684d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.RequiredType.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.cs index 584550263ba..15b9c4adab0 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOauth2Entity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public TypeOauth2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.Mutable.cs index bd02abb39af..942ca99321b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveOpenIdConnectUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.Mutable.cs index 5bc1594a8b1..7ce205b4941 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.Mutable.cs @@ -268,6 +268,31 @@ public void SetOpenIdConnectUrl(scoped in Corvus.OpenapiBenchmark.Current.JsonUr _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.cs index cdb65a75663..38ffcd8b99d 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredOpenIdConnectUrl.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredOpenIdConnectUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.Mutable.cs index 416517d5030..4edc40dfdf5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.Mutable.cs @@ -268,6 +268,31 @@ public void SetType(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Secu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.TypeEntity.cs index 07302504019..5af1302ddb6 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.cs index b6680465f7d..c8cc78c6dba 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.RequiredType.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.cs index 3143e5692b5..e099655c356 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.TypeOidcEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public TypeOidcEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.cs index eb35be6c903..6ec40fe1a4c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecurityScheme.cs @@ -528,6 +528,12 @@ private void CheckValidInstance() public SecurityScheme Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.Mutable.cs index 47cd9d62519..3bc2a5b8666 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.Mutable.cs @@ -858,6 +858,37 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FlowsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.OauthFlows.Mutable __corvusFlows)) + { + __corvusFlows.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.Mutable.cs index 1a92d8ed401..793f270a13c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.Mutable.cs @@ -300,6 +300,31 @@ public void SetRef(in Corvus.Text.Json.JsonElement.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.cs index c08889f88cb..f2a9e4187b4 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.RequiredRef.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredRef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.cs index bc34aa9f91a..ab41cedabdd 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SecuritySchemeOrReference.cs @@ -499,6 +499,12 @@ private void CheckValidInstance() public SecuritySchemeOrReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.Mutable.cs index 385248cc650..4965a12075c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.Mutable.cs @@ -388,6 +388,31 @@ public bool RemoveVariables() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.VariablesEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.VariablesEntity.cs index 7b2df630956..f95aed50c25 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.VariablesEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.VariablesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public VariablesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.cs index c7d450306f1..d6be567c257 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Server.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public Server Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerArray.cs index bdd8de4fee9..696bd77942a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerArray.cs @@ -35,11 +35,13 @@ public readonly partial struct OpenapiSchema public readonly partial struct ServerArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public ServerArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.JsonStringArray.cs index bccf4a530b4..19b391aa50b 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ServerVariable public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.Mutable.cs index a194be2a7f7..3345ca665ea 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.Mutable.cs @@ -388,6 +388,31 @@ public bool RemoveEnum() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.cs index 745c5acb9af..f779d964f13 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.ServerVariable.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public ServerVariable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SpecificationExtensions.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SpecificationExtensions.cs index 17478d174dc..15fe4db59a1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SpecificationExtensions.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.SpecificationExtensions.cs @@ -437,6 +437,12 @@ private void CheckValidInstance() public SpecificationExtensions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.DefaultValueFalse.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.DefaultValueFalse.cs index f67d588b66f..62ded4ff7b9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.DefaultValueFalse.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.DefaultValueFalse.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public DefaultValueFalse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.Mutable.cs index 9061ad5b56d..34430a92fca 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.Mutable.cs @@ -275,6 +275,36 @@ public bool RemoveExplode() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExplodeUtf8, out IJsonDocument? _, out int _)) + { + SetExplode(Corvus.OpenapiBenchmark.Current.OpenapiSchema.StylesForForm.ElseEntity.DefaultValueFalse.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.cs index 02d9d7f21c9..92cb0e09cff 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ElseEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.Mutable.cs index f64338255e8..59d1c795ea5 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.Mutable.cs @@ -273,6 +273,36 @@ public bool RemoveExplode() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExplodeUtf8, out IJsonDocument? _, out int _)) + { + SetExplode(Corvus.OpenapiBenchmark.Current.OpenapiSchema.StylesForForm.ElseEntity.DefaultValueFalse.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.Mutable.cs index 49ae83ea5d8..3e4b4c324b2 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.Mutable.cs @@ -266,6 +266,31 @@ public void SetStyle(scoped in Corvus.OpenapiBenchmark.Current.OpenapiSchema.Sty _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.StyleEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.StyleEntity.cs index b7439343533..e8252475a5c 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.StyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.StyleEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public StyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.cs index 5f33a660948..6ce2bfeebf6 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.RequiredStyle.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public RequiredStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.DefaultValueTrue.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.DefaultValueTrue.cs index a9fa35b7eac..d13efdbfb39 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.DefaultValueTrue.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.DefaultValueTrue.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public DefaultValueTrue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.Mutable.cs index 6e35dd96ac5..8aade69f02e 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.Mutable.cs @@ -275,6 +275,36 @@ public bool RemoveExplode() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExplodeUtf8, out IJsonDocument? _, out int _)) + { + SetExplode(Corvus.OpenapiBenchmark.Current.OpenapiSchema.StylesForForm.ThenEntity.DefaultValueTrue.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.cs index 290bf3be371..d99b1b59fdf 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.ThenEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.cs index 5564de28099..60c7e30705f 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.StylesForForm.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public StylesForForm Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.Mutable.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.Mutable.cs index 4659f9cb400..c06c6a6451a 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.Mutable.cs @@ -388,6 +388,37 @@ public void SetName(scoped in Corvus.OpenapiBenchmark.Current.JsonString.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExternalDocsUtf8, out Corvus.OpenapiBenchmark.Current.OpenapiSchema.ExternalDocumentation.Mutable __corvusExternalDocs)) + { + __corvusExternalDocs.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.cs index 51f4fcefdff..e27aab76255 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.Tag.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public Tag Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.TagArray.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.TagArray.cs index c5eeb7ccee7..3724bed0dc9 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.TagArray.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.TagArray.cs @@ -21,11 +21,13 @@ public readonly partial struct OpenapiSchema public readonly partial struct TagArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public TagArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.WebhooksEntity.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.WebhooksEntity.cs index 1b3b959bdee..758765994e6 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.WebhooksEntity.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.WebhooksEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public WebhooksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.cs b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.cs index 60fd2fc1add..7e0b1849db7 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.cs +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/OpenapiSchema.cs @@ -558,6 +558,12 @@ private void CheckValidInstance() public OpenapiSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/corvusjson-jsonschema.lock index beae534348f..1382a580ea1 100644 --- a/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.OpenapiBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:41.4286746\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:27.1944159\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/JsonString.cs index 24fa153a7ca..f3e403ff205 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileType.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileType.cs index 59c0bcb6e4f..77ef56d3bed 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileType.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileType.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public FileType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileTypes.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileTypes.cs index 0b47685d76a..a014e342480 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileTypes.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.FileTypes.cs @@ -21,11 +21,13 @@ public readonly partial struct PreCommitHooksSchema public readonly partial struct FileTypes #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public FileTypes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Language.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Language.cs index d33647d1c77..fd16920ebe1 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Language.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Language.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public Language Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.AlwaysRunEntity.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.AlwaysRunEntity.cs index e3c3c2960c4..e827ece07d0 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.AlwaysRunEntity.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.AlwaysRunEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public AlwaysRunEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.DescriptionEntity.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.DescriptionEntity.cs index 0c59c43e3f7..84a79d421d4 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.DescriptionEntity.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.DescriptionEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public DescriptionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.FailFastEntity.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.FailFastEntity.cs index 0b1082b2e2d..f4186379038 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.FailFastEntity.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.FailFastEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public FailFastEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.JsonStringArray.cs index c393eadaaaf..3ab32e0a9be 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct RequiredEntryAndIdAndLanguageAndName public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.LanguageVersionEntity.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.LanguageVersionEntity.cs index 171ddf23e06..1ff86ade2ce 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.LanguageVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.LanguageVersionEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public LanguageVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.MinimumPreCommitVersionEntity.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.MinimumPreCommitVersionEntity.cs index 74a50f3fffc..9627d88da00 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.MinimumPreCommitVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.MinimumPreCommitVersionEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public MinimumPreCommitVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.Mutable.cs index 7ece9cb15cb..41006d446e4 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.Mutable.cs @@ -1763,6 +1763,86 @@ public bool RemoveVerbose() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AlwaysRunUtf8, out IJsonDocument? _, out int _)) + { + SetAlwaysRun(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.AlwaysRunEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ArgsUtf8, out IJsonDocument? _, out int _)) + { + SetArgs(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalLiArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DescriptionUtf8, out IJsonDocument? _, out int _)) + { + SetDescription(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.DescriptionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExcludeUtf8, out IJsonDocument? _, out int _)) + { + SetExclude(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalExcludeFilesThatWereMatchedByFiles.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FailFastUtf8, out IJsonDocument? _, out int _)) + { + SetFailFast(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.FailFastEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilesUtf8, out IJsonDocument? _, out int _)) + { + SetFiles(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalThePatternOfFilesToRunOn.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LanguageVersionUtf8, out IJsonDocument? _, out int _)) + { + SetLanguageVersion(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.LanguageVersionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinimumPreCommitVersionUtf8, out IJsonDocument? _, out int _)) + { + SetMinimumPreCommitVersion(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.MinimumPreCommitVersionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PassFilenamesUtf8, out IJsonDocument? _, out int _)) + { + SetPassFilenames(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalIfFalseNoFilenamesWillBePassedToTheHook.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequireSerialUtf8, out IJsonDocument? _, out int _)) + { + SetRequireSerial(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.RequireSerialEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VerboseUtf8, out IJsonDocument? _, out int _)) + { + SetVerbose(Corvus.PreCommitHooksBenchmark.Current.PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.VerboseEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalExcludeFilesThatWereMatchedByFiles.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalExcludeFilesThatWereMatchedByFiles.cs index 8b30135fbb6..25c6bed2ca9 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalExcludeFilesThatWereMatchedByFiles.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalExcludeFilesThatWereMatchedByFiles.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public OptionalExcludeFilesThatWereMatchedByFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalIfFalseNoFilenamesWillBePassedToTheHook.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalIfFalseNoFilenamesWillBePassedToTheHook.cs index 5d9b2f86708..dbf82c5a92c 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalIfFalseNoFilenamesWillBePassedToTheHook.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalIfFalseNoFilenamesWillBePassedToTheHook.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public OptionalIfFalseNoFilenamesWillBePassedToTheHook Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalLiArray.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalLiArray.cs index 6ddb0efb092..48cc6474240 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalLiArray.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalLiArray.cs @@ -36,11 +36,13 @@ public readonly partial struct RequiredEntryAndIdAndLanguageAndName public readonly partial struct OptionalLiArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public OptionalLiArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalThePatternOfFilesToRunOn.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalThePatternOfFilesToRunOn.cs index 57fe8184f15..c1b2352c6a8 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalThePatternOfFilesToRunOn.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.OptionalThePatternOfFilesToRunOn.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public OptionalThePatternOfFilesToRunOn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.RequireSerialEntity.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.RequireSerialEntity.cs index 74e303ee544..36d34691210 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.RequireSerialEntity.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.RequireSerialEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RequireSerialEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.VerboseEntity.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.VerboseEntity.cs index deac1dec871..415ac7ed58a 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.VerboseEntity.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.VerboseEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public VerboseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.cs index 558183534eb..6c4021408a3 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.RequiredEntryAndIdAndLanguageAndName.cs @@ -740,6 +740,12 @@ private void CheckValidInstance() public RequiredEntryAndIdAndLanguageAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stage.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stage.cs index db80bbdfabf..52396ca4bab 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stage.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stage.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public Stage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stages.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stages.cs index 322eedb2758..eb178342129 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stages.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.Stages.cs @@ -21,11 +21,13 @@ public readonly partial struct PreCommitHooksSchema public readonly partial struct Stages #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public Stages Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.cs b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.cs index ca297a34e59..13a651f3138 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.cs +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/PreCommitHooksSchema.cs @@ -18,11 +18,13 @@ namespace Corvus.PreCommitHooksBenchmark.Current; public readonly partial struct PreCommitHooksSchema #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public PreCommitHooksSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/corvusjson-jsonschema.lock index c7352932f08..0ba2a1a257b 100644 --- a/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.PreCommitHooksBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:42.2781408\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:31.7056854\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonArray.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonArray.cs index bcce9d179b4..a2eaceb18b5 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonArray.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonArray.cs @@ -18,11 +18,13 @@ namespace Corvus.PulumiBenchmark.Current; public readonly partial struct JsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -67,6 +69,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -280,6 +297,12 @@ private void CheckValidInstance() public JsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonBoolean.cs index 5e1add84377..427b41e9177 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonInteger.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonInteger.cs index aa3f80c6ccc..b697fa243dd 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonInteger.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonInteger.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonString.cs index 5087df61ec0..f912a7b082d 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.Mutable.cs index e746cb635dd..5933ed37655 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.Mutable.cs @@ -278,6 +278,31 @@ public bool RemoveRefresh() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.RefreshEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.RefreshEntity.cs index 3e5ad16f428..fca55b2eca9 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.RefreshEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.RefreshEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public RefreshEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.cs index fee14a3610d..567f385e327 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AdditionalProjectOptions.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public AdditionalProjectOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AuthorIsAnOptionalAuthorThatCreatedThisProject.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AuthorIsAnOptionalAuthorThatCreatedThisProject.cs index d5c1ee2d79b..09b0ad975e1 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AuthorIsAnOptionalAuthorThatCreatedThisProject.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.AuthorIsAnOptionalAuthorThatCreatedThisProject.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AuthorIsAnOptionalAuthorThatCreatedThisProject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.Mutable.cs index 3c521da6b3c..95b9c4937fa 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.Mutable.cs @@ -278,6 +278,31 @@ public bool RemoveUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.cs index 6413e27cc4a..868c65cfffa 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.BackendOfTheProject.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public BackendOfTheProject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.AdditionalPropertiesEntity.cs index eae20dd88f0..56894a1c501 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.AdditionalPropertiesEntity.cs @@ -626,6 +626,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.IfTrueThisConfigurationValueShouldBeEncrypted.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.IfTrueThisConfigurationValueShouldBeEncrypted.cs index 8462ea6afc0..89de38d4d31 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.IfTrueThisConfigurationValueShouldBeEncrypted.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.IfTrueThisConfigurationValueShouldBeEncrypted.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IfTrueThisConfigurationValueShouldBeEncrypted Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.Mutable.cs index 512b969fcb5..6bb43b2bba3 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.Mutable.cs @@ -278,6 +278,36 @@ public bool RemoveSecret() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SecretUtf8, out IJsonDocument? _, out int _)) + { + SetSecret(Corvus.PulumiBenchmark.Current.PulumiSchema.ConfigEntity.IfTrueThisConfigurationValueShouldBeEncrypted.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.cs index a77f516dfd3..5306b386ea7 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigEntity.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public ConfigEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.Mutable.cs index 3a2d1f6c748..96dd5743e5d 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.Mutable.cs @@ -395,6 +395,37 @@ public void SetType(in Corvus.PulumiBenchmark.Current.PulumiSchema.Con _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemsUtf8, out Corvus.PulumiBenchmark.Current.PulumiSchema.ConfigItemsType.Mutable __corvusItems)) + { + __corvusItems.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.TypeEntity.cs index 43d6d3af8c5..7ff28193a2b 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.TypeEntity.cs @@ -449,6 +449,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.Mutable.cs index f11aad3c2ea..4e1afc4fd34 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.TypeEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.TypeEntity.cs index a1cb08ae3c0..90009a3070b 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.TypeEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.cs index bebeee51110..875143c092f 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.WithTypeArray.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public WithTypeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.cs index 7835df03d2c..9632418e18f 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigItemsType.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public ConfigItemsType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.Mutable.cs index 164cb4b4523..fd2f2896d92 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.Mutable.cs @@ -613,6 +613,37 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemsUtf8, out Corvus.PulumiBenchmark.Current.PulumiSchema.ConfigItemsType.Mutable __corvusItems)) + { + __corvusItems.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.cs index dc30912d34d..b1d5b25527f 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ConfigTypeDeclaration.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public ConfigTypeDeclaration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.DescriptionOfTheProject.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.DescriptionOfTheProject.cs index d615c7434ed..e5ec16d6a76 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.DescriptionOfTheProject.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.DescriptionOfTheProject.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DescriptionOfTheProject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.LicenseIsTheOptionalLicenseGoverningThisProjectSUsage.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.LicenseIsTheOptionalLicenseGoverningThisProjectSUsage.cs index fcfb191fa0a..9798b4554a7 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.LicenseIsTheOptionalLicenseGoverningThisProjectSUsage.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.LicenseIsTheOptionalLicenseGoverningThisProjectSUsage.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public LicenseIsTheOptionalLicenseGoverningThisProjectSUsage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.MainEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.MainEntity.cs index f5179231988..e22a20ad85d 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.MainEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.MainEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MainEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.Mutable.cs index d98dc49e480..41def6f63fe 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.Mutable.cs @@ -1258,6 +1258,61 @@ public bool RemoveWebsite() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BackendUtf8, out Corvus.PulumiBenchmark.Current.PulumiSchema.BackendOfTheProject.Mutable __corvusBackend)) + { + __corvusBackend.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigUtf8, out Corvus.PulumiBenchmark.Current.PulumiSchema.ConfigEntity.Mutable __corvusConfig)) + { + __corvusConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionsUtf8, out Corvus.PulumiBenchmark.Current.PulumiSchema.AdditionalProjectOptions.Mutable __corvusOptions)) + { + __corvusOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginsUtf8, out Corvus.PulumiBenchmark.Current.PulumiSchema.PluginsEntity.Mutable __corvusPlugins)) + { + __corvusPlugins.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TemplateUtf8, out Corvus.PulumiBenchmark.Current.PulumiSchema.ProjectTemplate.Mutable __corvusTemplate)) + { + __corvusTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.NameEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.NameEntity.cs index 35bca8b1fa9..7a91ec570fe 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.NameEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.Mutable.cs index ff4a743c5fd..186b7dcd474 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.Mutable.cs @@ -315,6 +315,31 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.cs index b388e2ae97a..997a92e13b7 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginOptions.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public PluginOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.Mutable.cs index 71b84a552bb..e9afc016f9c 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.Mutable.cs @@ -518,6 +518,31 @@ public bool RemoveProviders() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginOptionsArray.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginOptionsArray.cs index 21ad687f6ad..9563a9b2a02 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginOptionsArray.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginOptionsArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginsEntity public readonly partial struct PluginOptionsArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public PluginOptionsArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForLanArray.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForLanArray.cs index 3aa8f9aa2de..da482c31aea 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForLanArray.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForLanArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginsEntity public readonly partial struct PluginsForLanArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public PluginsForLanArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForResArray.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForResArray.cs index ed7e8b3a9dd..3cbeabe2b00 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForResArray.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.PluginsForResArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginsEntity public readonly partial struct PluginsForResArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public PluginsForResArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.cs index 3ef76e90099..f69b90ab7da 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.PluginsEntity.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public PluginsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.Name.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.Name.cs index d5f36bb7ebd..84501d82f29 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.Name.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.Name.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Mutable.cs index d298a33cbe5..011bf7d325a 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Mutable.cs @@ -301,6 +301,31 @@ public bool RemoveOptionsValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Name.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Name.cs index 64ac41060b3..fa71147ba12 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Name.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Name.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public Name Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Options.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Options.cs index 57897c7dc65..f0c17586d02 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Options.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.Options.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public Options Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.cs index 020b899a688..627404688e1 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.OneOf1Entity.cs @@ -302,6 +302,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.cs index 05d70b172e3..596c639a5f5 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectRuntimeInfo.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public ProjectRuntimeInfo Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.BooleanIndicatingIfTheConfigurationIsLabeledAsASecret.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.BooleanIndicatingIfTheConfigurationIsLabeledAsASecret.cs index 77efa4502d1..3d2123cd880 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.BooleanIndicatingIfTheConfigurationIsLabeledAsASecret.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.BooleanIndicatingIfTheConfigurationIsLabeledAsASecret.cs @@ -312,6 +312,12 @@ private void CheckValidInstance() public BooleanIndicatingIfTheConfigurationIsLabeledAsASecret Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.DescriptionOfTheConfig.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.DescriptionOfTheConfig.cs index 26cafa4d236..0901f4ff639 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.DescriptionOfTheConfig.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.DescriptionOfTheConfig.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public DescriptionOfTheConfig Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.Mutable.cs index 14073b94566..84e7f544bca 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.Mutable.cs @@ -450,6 +450,31 @@ public bool RemoveSecret() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.cs index 5a524c6ac82..1dc0a65eeb4 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.AdditionalPropertiesEntity.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.cs index 9eba00d83e6..400b98dec84 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ConfigToApplyToEachStackInTheProject.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public ConfigToApplyToEachStackInTheProject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.DescriptionOfTheTemplate.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.DescriptionOfTheTemplate.cs index 9aed18da519..141c3258cdc 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.DescriptionOfTheTemplate.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.DescriptionOfTheTemplate.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public DescriptionOfTheTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ImportantEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ImportantEntity.cs index 4bec05036ff..b30339e9771 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ImportantEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.ImportantEntity.cs @@ -308,6 +308,12 @@ private void CheckValidInstance() public ImportantEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.Mutable.cs index 97b47ed5a48..d44b80fbe87 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.Mutable.cs @@ -512,6 +512,31 @@ public bool RemoveQuickstart() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.QuickstartEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.QuickstartEntity.cs index b5916da85a8..2619e89d6e4 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.QuickstartEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.QuickstartEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public QuickstartEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.cs index 0680140b648..d80ed9e8865 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.ProjectTemplate.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public ProjectTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.SimpleConfigType.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.SimpleConfigType.cs index 80ce06a460e..376ca922b5f 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.SimpleConfigType.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.SimpleConfigType.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SimpleConfigType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.StackConfigDirEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.StackConfigDirEntity.cs index b4dcb50f5a3..a8600684a34 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.StackConfigDirEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.StackConfigDirEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public StackConfigDirEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.WebsiteEntity.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.WebsiteEntity.cs index 6d501d3e54e..1eda97846a4 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.WebsiteEntity.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.WebsiteEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WebsiteEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.cs b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.cs index b5004745761..4970d340a7d 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.cs +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/PulumiSchema.cs @@ -619,6 +619,12 @@ private void CheckValidInstance() public PulumiSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/corvusjson-jsonschema.lock index 2181c5b652f..746aac83f51 100644 --- a/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.PulumiBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:43.1588569\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:33.2505715\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonArray.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonArray.cs index 5bdce543e6a..364964c3628 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonArray.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonArray.cs @@ -18,11 +18,13 @@ namespace Corvus.SemanticReleaseBenchmark.Current; public readonly partial struct JsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -67,6 +69,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -280,6 +297,12 @@ private void CheckValidInstance() public JsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonBoolean.cs index a7decc32a9f..c71fea34bcc 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonString.cs index 5ba51f7304f..48a2f91076d 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.Mutable.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.Mutable.cs index 494ed86dd73..18dd9705d05 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.Mutable.cs @@ -374,6 +374,31 @@ public bool RemoveRange() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.PrereleaseEntity.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.PrereleaseEntity.cs index d3d11406f9c..541d876dea7 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.PrereleaseEntity.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.PrereleaseEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public PrereleaseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.cs index 6e3a3d790b9..04146308759 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.BranchObject.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public BranchObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.CiEntity.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.CiEntity.cs index 9d4ff2f7a41..4796b852e76 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.CiEntity.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.CiEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public CiEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.JsonStringArray.cs index 0778bd5a4a6..58939e76c99 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.JsonStringArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ExtendsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.cs index 0910476aef7..2c77d31b4fa 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.ExtendsEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ExtendsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.Mutable.cs index 889915dd7e6..0ed98a023ce 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.Mutable.cs @@ -779,6 +779,51 @@ public bool RemoveTagFormat() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BranchesUtf8, out IJsonDocument? _, out int _)) + { + SetBranches(Corvus.SemanticReleaseBenchmark.Current.SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CiUtf8, out IJsonDocument? _, out int _)) + { + SetCi(Corvus.SemanticReleaseBenchmark.Current.SemanticReleaseSchema.CiEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PluginsUtf8, out IJsonDocument? _, out int _)) + { + SetPlugins(Corvus.SemanticReleaseBenchmark.Current.SemanticReleaseSchema.PluginsEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagFormatUtf8, out IJsonDocument? _, out int _)) + { + SetTagFormat(Corvus.SemanticReleaseBenchmark.Current.SemanticReleaseSchema.TagFormatEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.PluginsEntity.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.PluginsEntity.cs index fdaf451d4c7..7508cf89345 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.PluginsEntity.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.PluginsEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public PluginsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.cs index 680ab9dd6a6..062ba2c29a4 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.PluginsEntityArray.cs @@ -39,11 +39,13 @@ public readonly partial struct SemanticReleaseSchema public readonly partial struct PluginsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -94,6 +96,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -307,6 +324,12 @@ private void CheckValidInstance() public PluginsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TagFormatEntity.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TagFormatEntity.cs index 03a022ce8d1..155ba631169 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TagFormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TagFormatEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public TagFormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.Type2Entity.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.Type2Entity.cs index 9f2c8c58e95..5e514f6c3f2 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.Type2Entity.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.Type2Entity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public Type2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.cs index a56f1a64ac3..b39c67afab8 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.Type2EntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct TheBranchesOnWhichReleasesShouldHappen public readonly partial struct Type2EntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public Type2EntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.cs index 2e591d5cb9b..232067d1965 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.TheBranchesOnWhichReleasesShouldHappen.cs @@ -498,6 +498,12 @@ private void CheckValidInstance() public TheBranchesOnWhichReleasesShouldHappen Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.cs b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.cs index d1e565d9463..73680be805e 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.cs +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/SemanticReleaseSchema.cs @@ -483,6 +483,12 @@ private void CheckValidInstance() public SemanticReleaseSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/corvusjson-jsonschema.lock index 26be6b1e391..fde631073b4 100644 --- a/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.SemanticReleaseBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:44.0007188\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:34.6760572\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/JsonString.cs index 7fe6a82b3a2..63916b9b026 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ClosedComment.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ClosedComment.cs index 245afa9a210..ddb737ea63d 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ClosedComment.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ClosedComment.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public ClosedComment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilClose.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilClose.cs index 8423fda6e61..7a8c6f2d5b3 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilClose.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilClose.cs @@ -454,6 +454,12 @@ private void CheckValidInstance() public DaysUntilClose Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilStale.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilStale.cs index 48c1bce1f23..ef085e1be1a 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilStale.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.DaysUntilStale.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public DaysUntilStale Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptAssignees.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptAssignees.cs index 4e9bdcd8341..1205c26e252 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptAssignees.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptAssignees.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ExemptAssignees Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptProjects.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptProjects.cs index 30af033f413..07fa8cbdb95 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptProjects.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.ExemptProjects.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ExemptProjects Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.JsonStringArray.cs index 83c30c7f1b5..5edbe8038e1 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.JsonStringArray.cs @@ -36,11 +36,13 @@ public readonly partial struct Configuration public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.LimitPerRun.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.LimitPerRun.cs index 5c8e9687f2c..ef0f0b95ad9 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.LimitPerRun.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.LimitPerRun.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public LimitPerRun Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.MarkComment.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.MarkComment.cs index 096cc9ecd76..208f2aad50e 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.MarkComment.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.MarkComment.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public MarkComment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Mutable.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Mutable.cs index cd478d389a0..eff73087d20 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Mutable.cs @@ -1088,6 +1088,76 @@ public bool RemoveUnmarkCommentValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DaysUntilCloseValueUtf8, out IJsonDocument? _, out int _)) + { + SetDaysUntilCloseValue(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.DaysUntilClose.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DaysUntilStaleValueUtf8, out IJsonDocument? _, out int _)) + { + SetDaysUntilStaleValue(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.DaysUntilStale.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExemptAssigneesValueUtf8, out IJsonDocument? _, out int _)) + { + SetExemptAssigneesValue(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.ExemptAssignees.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExemptLabelsUtf8, out IJsonDocument? _, out int _)) + { + SetExemptLabels(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExemptProjectsValueUtf8, out IJsonDocument? _, out int _)) + { + SetExemptProjectsValue(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.ExemptProjects.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LimitPerRunValueUtf8, out IJsonDocument? _, out int _)) + { + SetLimitPerRunValue(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.LimitPerRun.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MarkCommentValueUtf8, out IJsonDocument? _, out int _)) + { + SetMarkCommentValue(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.MarkComment.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OnlyLabelsUtf8, out IJsonDocument? _, out int _)) + { + SetOnlyLabels(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.OnlyLJsonSArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StaleLabelValueUtf8, out IJsonDocument? _, out int _)) + { + SetStaleLabelValue(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.StaleLabel.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Only.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Only.cs index 7d065812055..b8197d091b4 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Only.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.Only.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public Only Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.OnlyLJsonSArray.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.OnlyLJsonSArray.cs index b0f606df4ea..78117a50584 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.OnlyLJsonSArray.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.OnlyLJsonSArray.cs @@ -36,11 +36,13 @@ public readonly partial struct Configuration public readonly partial struct OnlyLJsonSArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -91,6 +93,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -304,6 +321,12 @@ private void CheckValidInstance() public OnlyLJsonSArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.StaleLabel.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.StaleLabel.cs index 2d71eb6cd4c..d6f1cb74776 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.StaleLabel.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.StaleLabel.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public StaleLabel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.UnmarkComment.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.UnmarkComment.cs index 9fd2dbd62b7..95648d9c99e 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.UnmarkComment.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.UnmarkComment.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public UnmarkComment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.cs index ba88d7c9f0b..25de43c78bc 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Configuration.cs @@ -603,6 +603,12 @@ private void CheckValidInstance() public Configuration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Mutable.cs index 992c830f903..4bbe46a8986 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.Mutable.cs @@ -1309,6 +1309,88 @@ public bool RemoveUnmarkComment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DaysUntilCloseUtf8, out IJsonDocument? _, out int _)) + { + SetDaysUntilClose(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.DaysUntilClose.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DaysUntilStaleUtf8, out IJsonDocument? _, out int _)) + { + SetDaysUntilStale(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.DaysUntilStale.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExemptAssigneesUtf8, out IJsonDocument? _, out int _)) + { + SetExemptAssignees(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.ExemptAssignees.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExemptLabelsUtf8, out IJsonDocument? _, out int _)) + { + SetExemptLabels(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.JsonStringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExemptProjectsUtf8, out IJsonDocument? _, out int _)) + { + SetExemptProjects(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.ExemptProjects.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LimitPerRunUtf8, out IJsonDocument? _, out int _)) + { + SetLimitPerRun(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.LimitPerRun.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MarkCommentUtf8, out IJsonDocument? _, out int _)) + { + SetMarkComment(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.MarkComment.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OnlyLabelsUtf8, out IJsonDocument? _, out int _)) + { + SetOnlyLabels(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.OnlyLJsonSArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StaleLabelUtf8, out IJsonDocument? _, out int _)) + { + SetStaleLabel(Corvus.StaleBenchmark.Current.StaleSchema.Configuration.StaleLabel.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IssuesUtf8, out Corvus.StaleBenchmark.Current.StaleSchema.Configuration.Mutable __corvusIssues)) + { + __corvusIssues.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PullsUtf8, out Corvus.StaleBenchmark.Current.StaleSchema.Configuration.Mutable __corvusPulls)) + { + __corvusPulls.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.cs b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.cs index 56e06584b6c..3ca39688035 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.cs +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/StaleSchema.cs @@ -667,6 +667,12 @@ private void CheckValidInstance() public StaleSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/corvusjson-jsonschema.lock index 55a39c58615..b28e2b302f8 100644 --- a/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.StaleBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:44.8383176\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:36.1502201\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/JsonString.cs index f464898f318..d3e68b7e386 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.Mutable.cs index ba2fbf64758..4a04e4e19f9 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.Mutable.cs @@ -311,6 +311,37 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentExposedElementsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentExposedElementsEntity.cs index bef3e14ac24..0dd87e98222 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentExposedElementsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentExposedElementsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DocumentExposedElementsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInterfacesEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInterfacesEntity.cs index 6338078f637..e1aa2eee17c 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInterfacesEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInterfacesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DocumentInterfacesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInternalElementsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInternalElementsEntity.cs index 1743350a46c..ee04ff76c1e 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInternalElementsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInternalElementsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DocumentInternalElementsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateElementsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateElementsEntity.cs index 2ecfb3c0bbe..0230d0e75a9 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateElementsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateElementsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DocumentPrivateElementsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateFieldsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateFieldsEntity.cs index d934e632e67..40265822286 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateFieldsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateFieldsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DocumentPrivateFieldsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.ExcludeFromPunctuationCheckArray.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.ExcludeFromPunctuationCheckArray.cs index babbbda701f..a411cdfa823 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.ExcludeFromPunctuationCheckArray.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.ExcludeFromPunctuationCheckArray.cs @@ -40,11 +40,13 @@ public readonly partial struct ConfigurationForDocumentationRulesSa1600 public readonly partial struct ExcludeFromPunctuationCheckArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public ExcludeFromPunctuationCheckArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.FileNamingConventionEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.FileNamingConventionEntity.cs index b19fc48b84c..cf438e84c29 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.FileNamingConventionEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.FileNamingConventionEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public FileNamingConventionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.Mutable.cs index 6183e2982d3..7612be16a90 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.Mutable.cs @@ -1071,6 +1071,91 @@ public bool RemoveXmlHeader() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompanyNameUtf8, out IJsonDocument? _, out int _)) + { + SetCompanyName(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheNameOfTheCompanyWhichAppearsInFileHeaders.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CopyrightTextUtf8, out IJsonDocument? _, out int _)) + { + SetCopyrightText(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCopyrightTextWhichShouldAppearInFileHeaders.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentExposedElementsUtf8, out IJsonDocument? _, out int _)) + { + SetDocumentExposedElements(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentExposedElementsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentInterfacesUtf8, out IJsonDocument? _, out int _)) + { + SetDocumentInterfaces(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInterfacesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentInternalElementsUtf8, out IJsonDocument? _, out int _)) + { + SetDocumentInternalElements(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentInternalElementsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentPrivateElementsUtf8, out IJsonDocument? _, out int _)) + { + SetDocumentPrivateElements(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateElementsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentPrivateFieldsUtf8, out IJsonDocument? _, out int _)) + { + SetDocumentPrivateFields(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.DocumentPrivateFieldsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentationCultureUtf8, out IJsonDocument? _, out int _)) + { + SetDocumentationCulture(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCultureThatShouldBeUsedForDocumentationComments.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExcludeFromPunctuationCheckUtf8, out IJsonDocument? _, out int _)) + { + SetExcludeFromPunctuationCheck(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.ExcludeFromPunctuationCheckArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FileNamingConventionUtf8, out IJsonDocument? _, out int _)) + { + SetFileNamingConvention(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.FileNamingConventionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeaderDecorationUtf8, out IJsonDocument? _, out int _)) + { + SetHeaderDecoration(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheTextUsedAsDecorationForTheCopyrightHeaderComment.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.XmlHeaderUtf8, out IJsonDocument? _, out int _)) + { + SetXmlHeader(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.XmlHeaderEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCopyrightTextWhichShouldAppearInFileHeaders.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCopyrightTextWhichShouldAppearInFileHeaders.cs index fbf26c8d87a..fcb6fcb06e3 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCopyrightTextWhichShouldAppearInFileHeaders.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCopyrightTextWhichShouldAppearInFileHeaders.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheCopyrightTextWhichShouldAppearInFileHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCultureThatShouldBeUsedForDocumentationComments.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCultureThatShouldBeUsedForDocumentationComments.cs index 0b0f12ca0df..5afe204f7e9 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCultureThatShouldBeUsedForDocumentationComments.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheCultureThatShouldBeUsedForDocumentationComments.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheCultureThatShouldBeUsedForDocumentationComments Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheNameOfTheCompanyWhichAppearsInFileHeaders.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheNameOfTheCompanyWhichAppearsInFileHeaders.cs index de532b865fb..7172fd4dd6d 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheNameOfTheCompanyWhichAppearsInFileHeaders.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheNameOfTheCompanyWhichAppearsInFileHeaders.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheNameOfTheCompanyWhichAppearsInFileHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheTextUsedAsDecorationForTheCopyrightHeaderComment.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheTextUsedAsDecorationForTheCopyrightHeaderComment.cs index efcd062c55e..fa49e0b977f 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheTextUsedAsDecorationForTheCopyrightHeaderComment.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.TheTextUsedAsDecorationForTheCopyrightHeaderComment.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheTextUsedAsDecorationForTheCopyrightHeaderComment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.VariablesEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.VariablesEntity.cs index 4051ce98d55..a30234ddb28 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.VariablesEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.VariablesEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public VariablesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.XmlHeaderEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.XmlHeaderEntity.cs index 181679af51e..e5f5f8427a8 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.XmlHeaderEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.XmlHeaderEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public XmlHeaderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.cs index 17d7e1de65c..955fb3410b6 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.cs @@ -546,6 +546,12 @@ private void CheckValidInstance() public ConfigurationForDocumentationRulesSa1600 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowConsecutiveUsingsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowConsecutiveUsingsEntity.cs index 828817cf0c3..b22fa2ebc8f 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowConsecutiveUsingsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowConsecutiveUsingsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowConsecutiveUsingsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowDoWhileOnClosingBraceEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowDoWhileOnClosingBraceEntity.cs index 48e14328e00..e8d2ca203f7 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowDoWhileOnClosingBraceEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowDoWhileOnClosingBraceEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowDoWhileOnClosingBraceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.Mutable.cs index a809a2f16b1..f5b1b1b5eaf 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.Mutable.cs @@ -348,6 +348,46 @@ public bool RemoveNewlineAtEndOfFile() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowConsecutiveUsingsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowConsecutiveUsings(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowConsecutiveUsingsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowDoWhileOnClosingBraceUtf8, out IJsonDocument? _, out int _)) + { + SetAllowDoWhileOnClosingBrace(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.AllowDoWhileOnClosingBraceEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NewlineAtEndOfFileUtf8, out IJsonDocument? _, out int _)) + { + SetNewlineAtEndOfFile(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.NewlineAtEndOfFileEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.NewlineAtEndOfFileEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.NewlineAtEndOfFileEntity.cs index dbf72d63839..26ed1de3137 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.NewlineAtEndOfFileEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.NewlineAtEndOfFileEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public NewlineAtEndOfFileEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.cs index c65aa1c67e4..951a421c234 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public ConfigurationForLayoutRulesSa1500 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowCommonHungarianPrefixesEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowCommonHungarianPrefixesEntity.cs index 8c7a2779194..ad9482d1179 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowCommonHungarianPrefixesEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowCommonHungarianPrefixesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowCommonHungarianPrefixesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.AllowedHungarianPrefixesEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.AllowedHungarianPrefixesEntity.cs index e26156d3cdc..f76b8271d53 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.AllowedHungarianPrefixesEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.AllowedHungarianPrefixesEntity.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public AllowedHungarianPrefixesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.cs index 7727fb48296..3cbd127db34 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.cs @@ -38,11 +38,13 @@ public readonly partial struct ConfigurationForNamingRulesSa1300 public readonly partial struct AllowedHungarianPrefixesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -93,6 +95,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public AllowedHungarianPrefixesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.AllowedNamespaceComponentsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.AllowedNamespaceComponentsEntity.cs index 0a15ddaad03..ba5e190deea 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.AllowedNamespaceComponentsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.AllowedNamespaceComponentsEntity.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public AllowedNamespaceComponentsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.cs index 9ad5744fa13..2ee6ad0e8d3 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.cs @@ -38,11 +38,13 @@ public readonly partial struct ConfigurationForNamingRulesSa1300 public readonly partial struct AllowedNamespaceComponentsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -93,6 +95,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public AllowedNamespaceComponentsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.IncludeInferredTupleElementNamesEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.IncludeInferredTupleElementNamesEntity.cs index a4a08318eae..e4b17a47f5c 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.IncludeInferredTupleElementNamesEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.IncludeInferredTupleElementNamesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IncludeInferredTupleElementNamesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.Mutable.cs index e86bc6ebfb1..9fe5a28ae23 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.Mutable.cs @@ -543,6 +543,56 @@ public bool RemoveTupleElementNameCasing() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowCommonHungarianPrefixesUtf8, out IJsonDocument? _, out int _)) + { + SetAllowCommonHungarianPrefixes(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowCommonHungarianPrefixesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowedHungarianPrefixesUtf8, out IJsonDocument? _, out int _)) + { + SetAllowedHungarianPrefixes(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedHungarianPrefixesEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowedNamespaceComponentsUtf8, out IJsonDocument? _, out int _)) + { + SetAllowedNamespaceComponents(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.AllowedNamespaceComponentsEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IncludeInferredTupleElementNamesUtf8, out IJsonDocument? _, out int _)) + { + SetIncludeInferredTupleElementNames(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.IncludeInferredTupleElementNamesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TupleElementNameCasingUtf8, out IJsonDocument? _, out int _)) + { + SetTupleElementNameCasing(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.SpecifiesTheCasingConventionUsedForTupleElementNames.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.SpecifiesTheCasingConventionUsedForTupleElementNames.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.SpecifiesTheCasingConventionUsedForTupleElementNames.cs index d67f4eb3c51..e9d8fab4241 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.SpecifiesTheCasingConventionUsedForTupleElementNames.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.SpecifiesTheCasingConventionUsedForTupleElementNames.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public SpecifiesTheCasingConventionUsedForTupleElementNames Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.cs index af40f068d0e..2d2b146d390 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public ConfigurationForNamingRulesSa1300 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.BlankLinesBetweenUsingGroupsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.BlankLinesBetweenUsingGroupsEntity.cs index 765dbecf696..b8a227b536e 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.BlankLinesBetweenUsingGroupsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.BlankLinesBetweenUsingGroupsEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public BlankLinesBetweenUsingGroupsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.ElementOrderEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.ElementOrderEntity.cs index 8123e11b9eb..ae0ae6172da 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.ElementOrderEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.ElementOrderEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ElementOrderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.cs index e4f9e4f2d37..fea0c258621 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.cs @@ -44,11 +44,13 @@ public readonly partial struct ConfigurationForOrderingRulesSa1200 public readonly partial struct ElementOrderEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -99,6 +101,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -312,6 +329,12 @@ private void CheckValidInstance() public ElementOrderEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.Mutable.cs index 4201a676ac0..37966bfac33 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.Mutable.cs @@ -459,6 +459,51 @@ public bool RemoveUsingDirectivesPlacement() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BlankLinesBetweenUsingGroupsUtf8, out IJsonDocument? _, out int _)) + { + SetBlankLinesBetweenUsingGroups(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.BlankLinesBetweenUsingGroupsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElementOrderUtf8, out IJsonDocument? _, out int _)) + { + SetElementOrder(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.ElementOrderEntityArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SystemUsingDirectivesFirstUtf8, out IJsonDocument? _, out int _)) + { + SetSystemUsingDirectivesFirst(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.SystemUsingDirectivesFirstEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UsingDirectivesPlacementUtf8, out IJsonDocument? _, out int _)) + { + SetUsingDirectivesPlacement(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.UsingDirectivesPlacementEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.SystemUsingDirectivesFirstEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.SystemUsingDirectivesFirstEntity.cs index 5c278de4384..3396e14f9f8 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.SystemUsingDirectivesFirstEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.SystemUsingDirectivesFirstEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public SystemUsingDirectivesFirstEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.UsingDirectivesPlacementEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.UsingDirectivesPlacementEntity.cs index a62a004e248..03e52ba5d58 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.UsingDirectivesPlacementEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.UsingDirectivesPlacementEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public UsingDirectivesPlacementEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.cs index 03e1e44f990..f02b939c5b8 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.cs @@ -375,6 +375,12 @@ private void CheckValidInstance() public ConfigurationForOrderingRulesSa1200 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.Mutable.cs index 70acb1c1314..61bbbe9426e 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.Mutable.cs @@ -243,6 +243,36 @@ public bool RemoveTopLevelTypes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TopLevelTypesUtf8, out IJsonDocument? _, out int _)) + { + SetTopLevelTypes(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.TopLevelTypesEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.TopLevelTypesEntity.cs index 1247e6750bd..6c676081156 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.TopLevelTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.TopLevelTypesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TopLevelTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.cs index 4fe98a6b59f..ff1d5ccf572 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.TopLevelTypesEntityArray.cs @@ -40,11 +40,13 @@ public readonly partial struct ConfigurationForOrderingRulesSa1400 public readonly partial struct TopLevelTypesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -95,6 +97,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -308,6 +325,12 @@ private void CheckValidInstance() public TopLevelTypesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.cs index bc64a112821..ff9b597da6a 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.cs @@ -294,6 +294,12 @@ private void CheckValidInstance() public ConfigurationForOrderingRulesSa1400 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.AllowBuiltInTypeAliasesEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.AllowBuiltInTypeAliasesEntity.cs index 7f5f1e35cca..baf3a0dd6be 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.AllowBuiltInTypeAliasesEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.AllowBuiltInTypeAliasesEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowBuiltInTypeAliasesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.Mutable.cs index 23a021d1184..30db46ed939 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.Mutable.cs @@ -207,6 +207,36 @@ public bool RemoveAllowBuiltInTypeAliases() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowBuiltInTypeAliasesUtf8, out IJsonDocument? _, out int _)) + { + SetAllowBuiltInTypeAliases(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.AllowBuiltInTypeAliasesEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.cs index 0acc8592c1e..3789c35b727 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.cs @@ -294,6 +294,12 @@ private void CheckValidInstance() public ConfigurationForReadabilityRulesSa1100 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForSpacingRulesSa1000.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForSpacingRulesSa1000.cs index 6b4567755b9..26e27d9e40f 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForSpacingRulesSa1000.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.ConfigurationForSpacingRulesSa1000.cs @@ -273,6 +273,12 @@ private void CheckValidInstance() public ConfigurationForSpacingRulesSa1000 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.Mutable.cs index 3f505dd673c..ae5b4ecd3d4 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.Mutable.cs @@ -339,6 +339,46 @@ public bool RemoveUseTabs() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentationSizeUtf8, out IJsonDocument? _, out int _)) + { + SetIndentationSize(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheIndentationSize.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TabSizeUtf8, out IJsonDocument? _, out int _)) + { + SetTabSize(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheTabWidth.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseTabsUtf8, out IJsonDocument? _, out int _)) + { + SetUseTabs(Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.IndentationConfiguration.UseTabsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheIndentationSize.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheIndentationSize.cs index e42082a5845..f10102f5a35 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheIndentationSize.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheIndentationSize.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public SpecifiesTheIndentationSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheTabWidth.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheTabWidth.cs index cc71a917c2c..4663f8e8a74 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheTabWidth.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.SpecifiesTheTabWidth.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public SpecifiesTheTabWidth Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.UseTabsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.UseTabsEntity.cs index 12f639f5fb5..1a12782ca81 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.UseTabsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.UseTabsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public UseTabsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.cs index 31d752d348e..1d509ee02df 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.IndentationConfiguration.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public IndentationConfiguration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.Mutable.cs index 6e64217975e..4ac63dbf4cb 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.Mutable.cs @@ -955,6 +955,73 @@ public bool RemoveSpacingRules() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentationRulesUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForDocumentationRulesSa1600.Mutable __corvusDocumentationRules)) + { + __corvusDocumentationRules.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndentationUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.IndentationConfiguration.Mutable __corvusIndentation)) + { + __corvusIndentation.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LayoutRulesUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForLayoutRulesSa1500.Mutable __corvusLayoutRules)) + { + __corvusLayoutRules.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaintainabilityRulesUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1400.Mutable __corvusMaintainabilityRules)) + { + __corvusMaintainabilityRules.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NamingRulesUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForNamingRulesSa1300.Mutable __corvusNamingRules)) + { + __corvusNamingRules.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OrderingRulesUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForOrderingRulesSa1200.Mutable __corvusOrderingRules)) + { + __corvusOrderingRules.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReadabilityRulesUtf8, out Corvus.StylecopBenchmark.Current.StylecopSchema.SettingsEntity.ConfigurationForReadabilityRulesSa1100.Mutable __corvusReadabilityRules)) + { + __corvusReadabilityRules.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.cs index 2402cdfd7cd..894293ebc9d 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.SettingsEntity.cs @@ -439,6 +439,12 @@ private void CheckValidInstance() public SettingsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.cs b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.cs index 8b46ca14c68..02ae0aaed69 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.cs +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/StylecopSchema.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public StylecopSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/corvusjson-jsonschema.lock index 11108c4b977..fdd5c6fec8e 100644 --- a/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.StylecopBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:45.8004700\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:37.8641797\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonBoolean.cs index fefed7e6746..15dd18cc7aa 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonNumber.cs index 47fe7b44dfc..49443a9755a 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonNumber.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonObject.cs index 8eb533ed33e..9ba46f40cb3 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonString.cs index 5ea943350e4..65664c55dea 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.AttachEntity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.AttachEntity.cs index 52b4752f455..7245631f2ad 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.AttachEntity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.AttachEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public AttachEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.Mutable.cs index 1f67978c396..68dc2a3a923 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.Mutable.cs @@ -1808,6 +1808,36 @@ public bool RemoveWindows() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AttachUtf8, out IJsonDocument? _, out int _)) + { + SetAttach(Corvus.TmuxinatorBenchmark.Current.TmuxinatorSchema.AttachEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.OneOf1Entity.cs index d6e4116baad..e5b5e86f7fd 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.OneOf1Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.cs index 5913c1d6d2e..ad9bfaadfb8 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.NameEntity.cs @@ -478,6 +478,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.TabsEntity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.TabsEntity.cs index ef8b6eec9e6..fdde3359fbd 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.TabsEntity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.TabsEntity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public TabsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.cs index c4cd90e4e14..b1561a74b60 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.TabsEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct TmuxinatorSchema public readonly partial struct TabsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TabsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.JsonStringArray.cs index 93bb759c07d..4eacfed2ca8 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct OneOf1Entity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.Mutable.cs index e4529f67abe..d340479ce13 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.Mutable.cs @@ -481,6 +481,31 @@ public bool RemovePre() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.JsonStringArray.cs index 70de21bd2f2..c144a26e451 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct PanesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.OneOf1Entity.cs index 027a8dfa7bf..48d7e18cfdf 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.OneOf1Entity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.cs index 3d49bd9892c..ea13aa7f744 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.PanesEntity.cs @@ -537,6 +537,12 @@ private void CheckValidInstance() public PanesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.cs index cb33234bc64..44299e40c42 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.PanesEntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct OneOf1Entity public readonly partial struct PanesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public PanesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.cs index 8f0c35ba4c9..bf604f9c247 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.OneOf1Entity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.cs index ee3177b6481..1818d343962 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.WindowsEntity.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public WindowsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.cs index 028f1f379ca..0f5e4431f4d 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.WindowsEntityArray.cs @@ -21,11 +21,13 @@ public readonly partial struct TmuxinatorSchema public readonly partial struct WindowsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public WindowsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.cs b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.cs index faae04dd5fe..f7274ebc726 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.cs +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/TmuxinatorSchema.cs @@ -747,6 +747,12 @@ private void CheckValidInstance() public TmuxinatorSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/corvusjson-jsonschema.lock index 6b1d7a9cfa8..2d4ff4b0925 100644 --- a/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.TmuxinatorBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:46.6962471\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:39.3833027\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonBoolean.cs index 3fddbc08bbf..e912f35a09e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonNumber.cs index 4fe9de37089..3017178b874 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonNumber.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonObject.cs index 2355a69be5f..7f32207508e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonString.cs index 868ed8edadc..b1f6a9dc1fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.Mutable.cs index 47bc19cc774..f0c68735558 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.SpecVersionEntity.cs index 4249e2b2806..8ebe5bb075c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.cs index a31b92bce9e..15b0798d3e4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.IfEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.ThenEntity.cs index 897dd7f3fda..b6ba1c26b0b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.ThenEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.cs index 7351753e0f9..33ee47bd6ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.ElseEntity.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.Mutable.cs index 0eda21a5f40..03b48a7ffaa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.Mutable.cs @@ -273,6 +273,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.SpecVersionEntity.cs index 4b59cb2f338..ebd2bace232 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.SpecVersionEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.cs index 020aabcd59e..2250aea905a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.IfEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.Mutable.cs index 8d25313188f..c250b92bef7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.Mutable.cs @@ -1256,6 +1256,79 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.KindEntity.cs index e6f46ae69b1..28e9d6f96c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.KindEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.Mutable.cs index c7935cdf9c9..bdc64efc6a3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveKind() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.cs index f003c9b885f..f11d81f298d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.Mutable.cs index 6d8a26bc7d9..c8621d6e344 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.Mutable.cs @@ -882,6 +882,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.El_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.El_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.Mutable.cs index 6e430111605..df866fff342 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.El_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.El_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.Mutable.cs @@ -254,6 +254,31 @@ public bool RemoveModules() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index 7ef250abe62..af0e82b177f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -696,6 +696,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs index 6bb5b0e6fe1..3b2fbe67c14 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs index 00936a3a3ae..06afe9321db 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs @@ -532,6 +532,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs index 767f1dbc308..df3120b68e0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs index 00e07b7d87e..79868c49233 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs index 064e3e2e448..bf26209f6de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs @@ -289,6 +289,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs index f9a26f3f3c2..69176394f9c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs index 854491342dc..a6d86f7c93f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.Mutable.cs index 27c06feaede..d1f6db9dd6a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.Mutable.cs @@ -700,6 +700,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs index 3ff5d2f2250..da1b8157e02 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs index d6044e96135..9f4515facd0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs @@ -629,6 +629,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs index 004b823f49b..6cee19006c8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs index 910dd76f2f3..20d1c0d446b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.cs index b8105529bd7..314eeaf44d2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.cs @@ -449,6 +449,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.Mutable.cs index fb3d661d069..936867dc7e8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs index a961ea09adf..37d573e5eb6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.cs index a4e13c00d0d..9591bd99385 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.IfEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs index fa1d27d9dde..2c90725ab88 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs @@ -649,6 +649,43 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.cs index e05849bc8f2..fe2869a1f41 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.cs @@ -300,6 +300,12 @@ private void CheckValidInstance() public Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.cs index 549fc63c012..923ce2a98fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public CollectionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.cs index ad98a9af17a..de3086c2a07 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public ConfigurationsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.cs index 743e2268ef8..469cb996568 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public DependenciesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable.cs index c967cf110f2..6508494e28c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable.cs @@ -444,6 +444,31 @@ public bool RemoveDependencies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.cs index f1a58c83e4b..89883104b46 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ShimsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs index 12b60904c67..a5b53aae411 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs index d59304aeed5..9b4715e647e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs index abdf36be475..9a063b55c0f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs @@ -627,6 +627,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs index 99e832aaa73..22843e6e1d9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs index 87b6efa4136..92a3b4dabaa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.cs index 2142f5beae7..36bbcc08906 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public ThenEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs index 41f3deaefa6..7ca7d24a3fd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs @@ -472,6 +472,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.Mutable.cs index 71fad2b18f8..eb0063f94e8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.TypeEntity.cs index 460646954b5..c3bf2fb5c8f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.TypeEntity.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.cs index 01aabd36cd1..2a68ecab061 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeProjectShim.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public WithTypeProjectShim Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs index cf97f65bc9f..90dc0a3e61e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs @@ -445,6 +445,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs index a1fbe7af90d..c9820da9c89 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs @@ -791,6 +791,49 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs index 3c423b72ced..cd7fe652493 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs index 47d904e422c..a4ee3053a21 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs @@ -530,6 +530,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs index 8a0025d34ef..161ebb877d3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs index eb695e35ca9..b6629d5cdc6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.cs index c068f497a46..5c1b74610f4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.Mutable.cs index ca536d887ff..7ee05dc14f7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs index 7f04496c320..08786d572bf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.cs index 36868539934..f4477cee515 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.IfEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.Mutable.cs index ed30e319924..5132a75b47b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.Mutable.cs @@ -698,6 +698,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 5441385ec8f..5e53cabc6a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs index bce7364ef98..b99f441f728 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.Mutable.cs index 9aa8e1ee66a..786a83a1f53 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.Mutable.cs @@ -627,6 +627,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs index 87efbe66b27..97e6159a0ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs index ac72eafcfec..3a08c2154cb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.cs index 28a2f7348ec..a5393aa8539 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.cs index 13fa21f7c59..1aed061f332 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.cs @@ -447,6 +447,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.Mutable.cs index 3af0b4cc3d1..547ba65c875 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.SpecVersionEntity.cs index d0e46b11893..62105af719a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.cs index f906d8b9811..28ed3d4dfe1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.IfEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable.cs index 9550ff47087..e21304afc11 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable.cs @@ -212,6 +212,31 @@ public bool RemovePath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.cs index 24c1870ded9..1ee932087b7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.cs @@ -294,6 +294,12 @@ private void CheckValidInstance() public MiddlewareEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs index e8db6d72af4..9690fb93eb3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs @@ -647,6 +647,43 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs index 2347582b805..a6a5d7f79df 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs @@ -353,6 +353,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.KindEntity.cs index b14d829ccba..1710cc93e99 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.KindEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.Mutable.cs index 2799fcf944a..ffebdf10e29 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.Mutable.cs @@ -625,6 +625,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.SpecVersionEntity.cs index c6c4d720722..7bef9a4bacd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.TypeEntity.cs index e71ec778b5a..c0a181da397 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.TypeEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.cs index 66a932fc376..56cc676fabe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ThenEntity2.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public ThenEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs index c243530e72b..c7eed72051e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs @@ -470,6 +470,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.Mutable.cs index 7be55b848a6..8621034451f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.TypeEntity.cs index 8d2789d802f..621a084950b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.TypeEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.cs index 2ff62d5e2a5..50d6e130162 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public WithTypeServerMiddleware Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs index 3571fb649bd..d5f083bb39f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs @@ -459,6 +459,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs index 2e447dc9567..4838ce1dd10 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs @@ -886,6 +886,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs index bba2c31ab51..01dadf0690a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs index b45f235efe9..dcb74fe463e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs @@ -528,6 +528,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs index 76a1ccc8e6c..2eaa31206df 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs index 51425188659..6d817e50ea6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs index 9992ef03d27..45bfa554447 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs index 5a3655b6bfc..0246ada9074 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs index b1025fa3b9a..54f9efc8e13 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs index 33fb347d6e6..eae57d8b610 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.IfEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.Mutable.cs index 65bdeafa00e..a717ebf65d2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.Mutable.cs @@ -696,6 +696,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index f42d3f49337..d7f4d68802b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -353,6 +353,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs index 1ee91cda83f..6c9d0e967b0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs index 622eefe03a6..25523a143d0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs @@ -625,6 +625,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs index e8798e04f1b..8e968c9cec4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs index 5e1acc6dd0b..357f120abb3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs index 5374c047867..61a19578395 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.cs index 19efd1fe5b3..e2525d7112c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.cs @@ -445,6 +445,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.Mutable.cs index 344cd15141c..5f81e59f84a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs index 9f113f8a70e..78f0566d20b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.SpecVersionEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.cs index 278a3e4db40..d5f1057dde4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.IfEntity.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs index bd5fca2b7a7..0db652e0f98 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs @@ -645,6 +645,43 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable.cs index 59493ca809f..806667153f3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemovePath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.cs index 3a0c44e9b64..9b305cf17f6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public TaskEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs index 61c7ff74944..d4d2b23fbbb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs index 5336e42758a..34c333204a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs index 7ad85f6088b..0fdfaab7041 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs @@ -623,6 +623,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs index 6122dcc69c7..14de808f374 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs index 8588c9619df..8e3ee6b5a32 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.cs index 1136e0db699..780a46fbee1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ThenEntity2.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public ThenEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs index ef78ad485b8..1878f67c3dd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.Mutable.cs index c54c038d807..30bac6f9235 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.TypeEntity.cs index c0aef889671..4c379d0839d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.TypeEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.cs index 26fa7c39e77..e6a53d2ce02 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.cs @@ -363,6 +363,12 @@ private void CheckValidInstance() public WithTypeTask Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.cs index a635405870b..a77e730c6fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.cs @@ -473,6 +473,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index bdd0b8999bf..0016eb20ea6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.cs index 956b81d86cf..85c1235bbae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.cs @@ -39,11 +39,13 @@ public readonly partial struct DependenciesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -93,6 +95,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -306,6 +323,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs index cb5804fbe76..329b902115b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.cs index 006b17dd576..a0ec00a3ec6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ModulesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs index 4e275f05241..63684a2a02f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.KindEntity.cs index 2a576ceeaac..4d75ed1f760 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.KindEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.Mutable.cs index 5d7c3fbbc5f..7352c5957d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.Mutable.cs @@ -846,6 +846,55 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.ExtensionName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.ExtensionName.cs index 3d309117790..e86fea312ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.ExtensionName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.ExtensionName.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public ExtensionName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.Mutable.cs index d862c33bfeb..ef8816d40f5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.Mutable.cs @@ -262,6 +262,31 @@ public void SetName(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.cs index a1ed404f726..cf80edaa6ab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RequiredKindAndMetadataAndSpecVersionAndTypeRequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable.cs index 981c6ecfbc9..245c487706e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable.cs @@ -258,6 +258,31 @@ public void SetName(scoped in Corvus.Ui5Benchmark.Current.JsonString.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.cs index 392aa5177bd..6c2cb918a38 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.cs @@ -309,6 +309,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.SpecVersionEntity.cs index abf5cfc109a..76e23ba87b8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.SpecVersionEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.TypeEntity.cs index 4b042b7f1a4..e225dc3a821 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.TypeEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.Mutable.cs index f30900f489e..61361029de8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.Mutable.cs @@ -279,6 +279,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.TypeEntity.cs index 3f1fbd76b92..efa618a53d3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.TypeEntity.cs @@ -272,6 +272,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.cs index bb5b9adf2a7..4906e0ad0d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.WithTypeNull.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public WithTypeNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.cs index e186236aaec..8bd2d4c9708 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.cs @@ -491,6 +491,12 @@ private void CheckValidInstance() public RequiredKindAndMetadataAndSpecVersionAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.cs index ad16455a12c..d8913807222 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.ElseEntity.cs @@ -469,6 +469,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.KindEntity.cs index d073c36c9a5..55fc8b6d749 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.KindEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.Mutable.cs index 3a81974e9bb..c4a9a10e299 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveKind() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.cs index 39f944bf2db..f388f6ad57b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.IfEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.KindEntity.cs index 9d4c1814c88..60d546fa95d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.KindEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.Mutable.cs index 5f750409006..c928532f317 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.Mutable.cs @@ -1259,6 +1259,79 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MiddlewareUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.MiddlewareEntity.Mutable __corvusMiddleware)) + { + __corvusMiddleware.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShimsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable __corvusShims)) + { + __corvusShims.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TaskUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TaskEntity.Mutable __corvusTask)) + { + __corvusTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.Mutable.cs index 99f279f644d..3be248fd415 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.Mutable.cs @@ -339,6 +339,43 @@ public bool RemoveBundleOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleDefinitionUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.Mutable __corvusBundleDefinition)) + { + __corvusBundleDefinition.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleOptionsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.Mutable __corvusBundleOptions)) + { + __corvusBundleOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.cs index 6fc20eb1238..a6a25cd1ed2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.BuilderBundles24Entity.cs @@ -304,6 +304,12 @@ private void CheckValidInstance() public BuilderBundles24Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.cs index a579739f0d3..d050628eb5a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles24Array.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public BuilderBundles24Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.Mutable.cs index 702677919dc..902e059dddf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.Mutable.cs @@ -339,6 +339,43 @@ public bool RemoveBundleOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleDefinitionUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.Mutable __corvusBundleDefinition)) + { + __corvusBundleDefinition.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleOptionsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.Mutable __corvusBundleOptions)) + { + __corvusBundleOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.cs index 4972f60f4ea..a2d7c60b9e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.BuilderBundles30Entity.cs @@ -304,6 +304,12 @@ private void CheckValidInstance() public BuilderBundles30Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.cs index d2bc7f28337..fa7c47e6bf7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundles30Array.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public BuilderBundles30Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.Mutable.cs index 9af98eaab0e..81d6d6b607b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.Mutable.cs @@ -339,6 +339,43 @@ public bool RemoveBundleOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleDefinitionUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.Mutable __corvusBundleDefinition)) + { + __corvusBundleDefinition.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleOptionsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.Mutable __corvusBundleOptions)) + { + __corvusBundleOptions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.cs index 03c6e7c8f52..db18e67dcad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.BuilderBundlesEntity.cs @@ -304,6 +304,12 @@ private void CheckValidInstance() public BuilderBundlesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.cs index c7f3dc10e83..ba533bf624c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesArray.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public BuilderBundlesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.AddTryCatchRestartWrapperEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.AddTryCatchRestartWrapperEntity.cs index 601fb9cde8f..721f995bd15 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.AddTryCatchRestartWrapperEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.AddTryCatchRestartWrapperEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AddTryCatchRestartWrapperEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.DecorateBootstrapModuleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.DecorateBootstrapModuleEntity.cs index 118f57c66b3..e4911efcbcd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.DecorateBootstrapModuleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.DecorateBootstrapModuleEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DecorateBootstrapModuleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.Mutable.cs index 76a8246ed43..2e62d0e391a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.Mutable.cs @@ -509,6 +509,61 @@ public bool RemoveUsePredefineCalls() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AddTryCatchRestartWrapperUtf8, out IJsonDocument? _, out int _)) + { + SetAddTryCatchRestartWrapper(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.AddTryCatchRestartWrapperEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DecorateBootstrapModuleUtf8, out IJsonDocument? _, out int _)) + { + SetDecorateBootstrapModule(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.DecorateBootstrapModuleEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NumberOfPartsUtf8, out IJsonDocument? _, out int _)) + { + SetNumberOfParts(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.NumberOfPartsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptimizeUtf8, out IJsonDocument? _, out int _)) + { + SetOptimize(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.OptimizeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SourceMapUtf8, out IJsonDocument? _, out int _)) + { + SetSourceMap(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.SourceMapEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UsePredefineCallsUtf8, out IJsonDocument? _, out int _)) + { + SetUsePredefineCalls(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.UsePredefineCallsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.NumberOfPartsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.NumberOfPartsEntity.cs index d1f6695527f..f94183068a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.NumberOfPartsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.NumberOfPartsEntity.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public NumberOfPartsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.OptimizeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.OptimizeEntity.cs index 93a58ef80e9..ec1664125c2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.OptimizeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.OptimizeEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OptimizeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.SourceMapEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.SourceMapEntity.cs index ab666d049b3..73f58c89c1b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.SourceMapEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.SourceMapEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public SourceMapEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.UsePredefineCallsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.UsePredefineCallsEntity.cs index f8a7b32a1c7..82f6c1f1c2e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.UsePredefineCallsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.UsePredefineCallsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public UsePredefineCallsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.cs index 64ace3bc9ef..8a0ef1440f6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptions30Entity.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public BuilderBundlesBundleOptions30Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.AddTryCatchRestartWrapperEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.AddTryCatchRestartWrapperEntity.cs index 1d17bf7220e..0f8c3aef66b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.AddTryCatchRestartWrapperEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.AddTryCatchRestartWrapperEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AddTryCatchRestartWrapperEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.DecorateBootstrapModuleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.DecorateBootstrapModuleEntity.cs index d6a3cd37f04..c4a1b953621 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.DecorateBootstrapModuleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.DecorateBootstrapModuleEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DecorateBootstrapModuleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.Mutable.cs index bde521fffa7..9744e27c695 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.Mutable.cs @@ -448,6 +448,56 @@ public bool RemoveUsePredefineCalls() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AddTryCatchRestartWrapperUtf8, out IJsonDocument? _, out int _)) + { + SetAddTryCatchRestartWrapper(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.AddTryCatchRestartWrapperEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DecorateBootstrapModuleUtf8, out IJsonDocument? _, out int _)) + { + SetDecorateBootstrapModule(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.DecorateBootstrapModuleEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NumberOfPartsUtf8, out IJsonDocument? _, out int _)) + { + SetNumberOfParts(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.NumberOfPartsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptimizeUtf8, out IJsonDocument? _, out int _)) + { + SetOptimize(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.OptimizeEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UsePredefineCallsUtf8, out IJsonDocument? _, out int _)) + { + SetUsePredefineCalls(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.UsePredefineCallsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.NumberOfPartsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.NumberOfPartsEntity.cs index bca45df02b8..176abfc114b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.NumberOfPartsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.NumberOfPartsEntity.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public NumberOfPartsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.OptimizeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.OptimizeEntity.cs index 4740dd9617b..f59f3180f04 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.OptimizeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.OptimizeEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OptimizeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.UsePredefineCallsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.UsePredefineCallsEntity.cs index 01f2437fed1..f216321aebf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.UsePredefineCallsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.UsePredefineCallsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public UsePredefineCallsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.cs index 39e736ddb63..a6f7d3a859d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderBundlesBundleOptionsEntity.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public BuilderBundlesBundleOptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.JsonStringArray.cs index 344cbd17eed..fbd3b2978c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderComponentPreloadEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.Mutable.cs index fdb1651653f..0b9805dfeea 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.Mutable.cs @@ -337,6 +337,31 @@ public bool RemovePaths() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.PathsJsonSArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.PathsJsonSArray.cs index f502a2febcd..51c7de0e1f8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.PathsJsonSArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.PathsJsonSArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderComponentPreloadEntity public readonly partial struct PathsJsonSArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public PathsJsonSArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.cs index f470f836c0d..ee70b4766df 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.cs @@ -302,6 +302,12 @@ private void CheckValidInstance() public BuilderComponentPreloadEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.JsonStringArray.cs index eaa9b8aee9d..e05e46df0b7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderComponentPreloadSpecVersion23Entity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable.cs index c96cb2e85ca..c4c200f5cc8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable.cs @@ -434,6 +434,31 @@ public bool RemovePaths() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.NamespacesArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.NamespacesArray.cs index 9e23c05681d..6fea68cb866 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.NamespacesArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.NamespacesArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderComponentPreloadSpecVersion23Entity public readonly partial struct NamespacesArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public NamespacesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.PathsJsonSArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.PathsJsonSArray.cs index 7d2ece5e192..afa1d48cf04 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.PathsJsonSArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.PathsJsonSArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderComponentPreloadSpecVersion23Entity public readonly partial struct PathsJsonSArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public PathsJsonSArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.cs index 30bb6a64337..e6f34ea63c5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BuilderComponentPreloadSpecVersion23Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.JsonStringArray.cs index 6c14451e3c4..bf4e7e8916f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderLibraryPreloadEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable.cs index 49cc7d247e7..3f91877ce9c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable.cs @@ -240,6 +240,31 @@ public bool RemoveExcludes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.cs index 642e1fa24bf..8c2375d5728 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.cs @@ -286,6 +286,12 @@ private void CheckValidInstance() public BuilderLibraryPreloadEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.JsonStringArray.cs index d5aa8dbb91a..5c8c3a003ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderMinificationEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable.cs index c5e063798d3..d43ea0e1a55 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable.cs @@ -240,6 +240,31 @@ public bool RemoveExcludes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.cs index 81ccfce496e..2027b3f460c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.cs @@ -286,6 +286,12 @@ private void CheckValidInstance() public BuilderMinificationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.JsonStringArray.cs index e04b742a5a3..06b20ba3f0f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderResourcesEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable.cs index 1ada1bf6ca4..a943a2e0371 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable.cs @@ -240,6 +240,31 @@ public bool RemoveExcludes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.cs index 8e418e1db53..aa2ac45163a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.cs @@ -286,6 +286,12 @@ private void CheckValidInstance() public BuilderResourcesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.IncludeDepArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.IncludeDepArray.cs index 9f4ca132225..8ffe15110c2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.IncludeDepArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.IncludeDepArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderSettingsEntity public readonly partial struct IncludeDepArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public IncludeDepArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.JsonStringArray.cs index d8d4989b61b..c722bb4802a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct BuilderSettingsEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable.cs index 6c99bbb5d07..ee2a976eea2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable.cs @@ -434,6 +434,31 @@ public bool RemoveIncludeDependencyTree() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.cs index 8eb858399ea..e9fb3803272 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BuilderSettingsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.Mutable.cs index e35706fbd28..7362b8a2f0b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.Mutable.cs @@ -348,6 +348,31 @@ public void SetName(scoped in Corvus.Ui5Benchmark.Current.JsonString.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.cs index ad9ab483585..608c1525961 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredAfterTaskAndName.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public RequiredAfterTaskAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.Mutable.cs index 3b3e2d2e069..6d13cefbc1d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.Mutable.cs @@ -348,6 +348,31 @@ public void SetName(scoped in Corvus.Ui5Benchmark.Current.JsonString.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.cs index ff35b4500d1..a8b02ab118e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.RequiredBeforeTaskAndName.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public RequiredBeforeTaskAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.cs index 3824943743b..ff1f454d4ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.CustomTasksEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public CustomTasksEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.cs index 4bdc72ba708..42a1504bdca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RequiredSpecVersionAndType public readonly partial struct CustomTasksEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public CustomTasksEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.cs index 07351306856..581391aebe4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SignatureTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.cs index 094e66cd37e..84d62180c31 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SignatureTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.cs index afac2cf5743..ac6196e0694 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SignatureTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.cs index 3ebb08ee579..edf9693c5fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SignatureTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.cs index 68816532b15..f18bfe0269d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SignatureTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs index 3230b45a533..b16e150f23b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public ConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 401ee7593df..d1105cbbd55 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs index cd887bf0944..0a6379ef2ff 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs @@ -250,6 +250,37 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.Mutable.cs index 09eb378eae2..665add95b24 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.Mutable.cs @@ -347,6 +347,43 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_.__RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_.__RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable1.cs index dd5a15c9e0b..de67f579cd0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_.__RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_.__RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable1.cs @@ -275,6 +275,31 @@ public bool RemoveTest() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity1.cs index 2c3ff8a6d27..c11d2c2809c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity1.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity2.cs index bacdd6eb778..d7a98e7085d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity2.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs index a043dacee66..4539495adc1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs index 378a6f5eb9c..3b4d440bc07 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.cs index fb03db89d18..8eed93aa971 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs index 1fb5b929e73..40655cf5543 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity1.cs index 9b7f2ead293..9a8e1cd0502 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity1.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs index d9d7f8f94ae..3c93b18813e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs @@ -890,6 +890,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs index 894ee4476d4..cbf09510ba3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs @@ -296,6 +296,12 @@ private void CheckValidInstance() public BuilderSpecVersion25Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.cs index 01333c2b594..a649c111cd5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.cs @@ -312,6 +312,12 @@ private void CheckValidInstance() public BuilderSpecVersion31Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs index 15fba360133..3d783bbdcf8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs @@ -483,6 +483,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs index ddd27df7729..bb8fc4f3c91 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs @@ -289,6 +289,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs index b8f8a9b865e..333732f50d3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs index 976ba63db48..ebab69e1059 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs @@ -894,6 +894,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs index 143e152ebbe..f5258ce3343 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs index 97dfbc735c0..fc6d04685e0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs @@ -481,6 +481,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs index f8045883d25..54ca31c79f2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs index 0efbcb0af64..9d805dc8a71 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs index 7652080632d..b6813ccf497 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs index 6166257702d..750ebae99a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs @@ -863,6 +863,55 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs index fb50d2bec86..8a42202d9b6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs @@ -250,6 +250,37 @@ public bool RemoveConfiguration() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigurationUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable __corvusConfiguration)) + { + __corvusConfiguration.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs index 7e4a289dcff..0ae911b9a02 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs @@ -296,6 +296,12 @@ private void CheckValidInstance() public ResourcesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs index 80d16379f7a..11724b33a9b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs index 4828c9b163a..a9b699fd589 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs @@ -821,6 +821,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs index eeb804858f6..55363ee326d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs index f26e43979f2..d784b4d64f7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs index d77138e674c..e4ead9a0302 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs @@ -494,6 +494,12 @@ private void CheckValidInstance() public RequiredMetadataAndSpecVersionAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.Mutable.cs index 30fc928808b..c820e25a671 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.TypeEntity.cs index 0936c55c156..dc38ad3e4b6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.TypeEntity.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.cs index 0c07e7c43a8..466eef73952 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.WithTypeModule.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public WithTypeModule Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs index 54ea3ec2702..0cd3e4d33e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs @@ -477,6 +477,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index 797e6474251..12cc18d85f7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -985,6 +985,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs index c75d1df1956..ddd3c0418f4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs @@ -345,6 +345,37 @@ public bool RemoveResources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs index db4edf1d48e..f83a54984a9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public BuilderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs index ec2b92b839d..d8804760c58 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs @@ -442,6 +442,43 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs index 6873c9f7fb3..0e83cae4411 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public BuilderSpecVersion25Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs index 390996f4b16..fb5bb9e0cd5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs index a4d91197812..7036bfe8ec4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs @@ -289,6 +289,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs index 6e21ca853e2..b4483ec2cab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs index 90a4bb39bb5..2d0c9c354b8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs @@ -991,6 +991,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs index 6007fa6b797..09fcaf53dd3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs index 4c2e76378b0..ca424f9b9ac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs index d3f9568c019..f611e54084a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs index f48e0a13ab2..4c4add5f738 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs index 858c7b7d462..d6a2ca3b64d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs index 7053f362071..87bf2ac6120 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs @@ -989,6 +989,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs index c2d4475ac6e..86e14a2153f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs index add9a11fa04..7e9e0504fc3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs @@ -918,6 +918,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs index 9bccbb5c9fa..900e22aec28 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs index a7a5dc32d68..f866d5502cc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs index 02663e53794..4d7f8dcca6a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs index 913c3eb203f..37b50f9b0e9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs @@ -495,6 +495,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs index 80a2303afbc..f352446d412 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs index e321a90b7a6..1859684b3f3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs index ef1917786d0..342067bb6a8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs index e840dd5bc80..715a260bf72 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs @@ -958,6 +958,61 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs index 0acb643a319..0d7e9da7d1e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs @@ -353,6 +353,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs index 69f14fdb8ad..52c4bfd693d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs index 9e43bc7a8cd..c8be68fc98d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs @@ -916,6 +916,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs index cb0c5996f66..961dc7dd721 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs index 7f064deed76..2268b216f5d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs index 415fbe44d52..2d8c04975f5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs index ddde6d6b303..1fd60b79097 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs @@ -508,6 +508,12 @@ private void CheckValidInstance() public RequiredMetadataAndSpecVersionAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.Mutable.cs index 14da3c9e92f..385b0a55d40 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.TypeEntity.cs index 6ea44a1f989..94c5dffbf6b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.TypeEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.cs index d894c8b5ccc..3f64dde6fde 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public WithTypeThemeLibrary Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs index 69e778821c3..274144b88e5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs @@ -491,6 +491,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs index 860b91e68b1..5c6bfed72af 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs @@ -983,6 +983,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs index 024b85e4c52..51aca8f8a5a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 8c172987dfb..77a7eaf1c15 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs index 4936e91c0f8..05117269582 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs index 54ea40b751c..8e88091fbd5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs index ba3f369c06c..01caba3de8a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs index bd8b4c0c4cf..bed0ffdb419 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs index f8a820fa53d..1b98f8dbb53 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs index 2a2d118915a..21f74595405 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs @@ -414,6 +414,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs index 0c77450029f..c564c156252 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs index f1cec0977f9..6038a92ceec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs index 301fc7462a9..a6d4b880d0c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs @@ -430,6 +430,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs index b6dd393f5e3..070735ce627 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs index 048586bac39..524eb2743a5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs index fb7cfa0450d..a4087f8180d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs index ad687dbbd28..863e218b921 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs index f6ed447fdc4..dde86737124 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs @@ -375,6 +375,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs index 21833ed61a1..6280911d5eb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs @@ -827,6 +827,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index 6fb02acc638..34ea540fb8d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -995,6 +995,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs index bdf0a49b409..3552f5b7abe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs @@ -922,6 +922,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs index d49278b8bcd..a46950859fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs @@ -924,6 +924,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs index 0ee9ceeaa45..9cc59e80223 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs @@ -634,6 +634,49 @@ public bool RemoveResources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsdocUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable __corvusJsdoc)) + { + __corvusJsdoc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs index cf42dd5e021..520a0e23bbd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs @@ -356,6 +356,12 @@ private void CheckValidInstance() public BuilderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.JsonStringArray.cs index f3010d7cbdf..5cf12011120 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.JsonStringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct BuilderJsdocEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -87,6 +89,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -300,6 +317,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable.cs index 5b0c30f2b6c..15e5235f277 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable.cs @@ -246,6 +246,31 @@ public bool RemoveExcludes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.cs index 6ce9c71e851..57ab5d8a161 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public BuilderJsdocEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs index ffa7a3d5566..23620bfc6e2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs @@ -731,6 +731,55 @@ public bool RemoveResources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsdocUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable __corvusJsdoc)) + { + __corvusJsdoc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibraryPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable __corvusLibraryPreload)) + { + __corvusLibraryPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs index 511eb6f7042..7a8ced9d2e6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public BuilderSpecVersion23Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs index 25ce8d299d0..e73b3095b39 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs @@ -731,6 +731,55 @@ public bool RemoveResources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsdocUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable __corvusJsdoc)) + { + __corvusJsdoc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibraryPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable __corvusLibraryPreload)) + { + __corvusLibraryPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs index 2f689845dcc..7059646e5e5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public BuilderSpecVersion24Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs index 31d875d24ed..a77ac54bf4f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs @@ -828,6 +828,61 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsdocUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable __corvusJsdoc)) + { + __corvusJsdoc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibraryPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable __corvusLibraryPreload)) + { + __corvusLibraryPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs index 45d1f302b13..cd910145c79 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public BuilderSpecVersion25Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs index 8cba0395ddb..93007a8eab0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs @@ -925,6 +925,67 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsdocUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable __corvusJsdoc)) + { + __corvusJsdoc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibraryPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable __corvusLibraryPreload)) + { + __corvusLibraryPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinificationUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable __corvusMinification)) + { + __corvusMinification.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs index 81834cf54ef..e3542e2c89c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public BuilderSpecVersion26Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs index 632d8111680..2570faa78bb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs @@ -925,6 +925,67 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.JsdocUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderJsdocEntity.Mutable __corvusJsdoc)) + { + __corvusJsdoc.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibraryPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderLibraryPreloadEntity.Mutable __corvusLibraryPreload)) + { + __corvusLibraryPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinificationUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable __corvusMinification)) + { + __corvusMinification.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs index 02c40bb5e2d..9aed12ed738 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public BuilderSpecVersion30Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs index 5c0bf72eaeb..51b5732e48e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs @@ -499,6 +499,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs index 6a5edc8bd38..f364e4ffc78 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs @@ -289,6 +289,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs index d240d2a915c..44803a6b755 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index 01ff3ce3a6a..8a75d85a031 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -991,6 +991,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs index 0c2662c585f..40501191a5a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs index 4ab3f503eab..cfeb39032b8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs index 2499f4aeb9f..0c7559f6097 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs index 4f13671d780..810371e3712 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs index 4d7fd4c0979..3c5787c318d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs index b28255ee172..28bafccf498 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs @@ -989,6 +989,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs index a46bef49836..4c414c18e41 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs index 25de6c1f73d..94dcc8f8e24 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs @@ -918,6 +918,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs index d829e0424c1..d8bce302aaf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs index 4c22877b62e..14cc83701c6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs index 4f6f42de271..18182c0a729 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs @@ -495,6 +495,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs index 79944bde2e5..7892b01020f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs index e03c66f34fa..c8fc6170814 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs index 0d9217f76dc..5c7d5b89336 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs index 806adcc660d..4e1914de4fb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs @@ -987,6 +987,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 11568f96b76..e9aaa4e5b15 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -353,6 +353,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs index 4f5d5691137..25454b2938f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs index 4d10b132859..60f5136ffe9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs @@ -916,6 +916,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs index 517652cfe8f..c10292b1465 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs index f3a801b219b..a6ec8fef7b0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs index e55a545122c..3cd94dc7335 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs index 6610ff22570..d94835ce8e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs index c6139c3882f..53fdd15d8e9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs index 629a3cbd91c..aae384f5149 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs index 01b6f788f9d..5a38455b194 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs index a34ae0e892e..3e89642dcbd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs @@ -956,6 +956,61 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs index 5a37058a800..fcd2c64d7c1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs @@ -314,6 +314,42 @@ public bool RemovePropertiesFileSourceEncoding() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropertiesFileSourceEncodingUtf8, out IJsonDocument? _, out int _)) + { + SetPropertiesFileSourceEncoding(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PathsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable __corvusPaths)) + { + __corvusPaths.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs index ab5268a4910..84fd2453441 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs @@ -312,6 +312,12 @@ private void CheckValidInstance() public PathsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs index d6ab5ff7f69..da896a19531 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public ConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs index 30c8fa3b119..954418e8a7d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs @@ -246,6 +246,37 @@ public bool RemoveConfiguration() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigurationUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable __corvusConfiguration)) + { + __corvusConfiguration.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs index e84882d69db..59e08b1df60 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public ResourcesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs index 6f138317b1f..bc8033c36e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs index 29b73a8d6ea..8e03228db7c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs index 12e2c1912e8..4673dbf51c4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs @@ -914,6 +914,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs index 65ffe405f00..2d7ebd1fb4b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs index 524073111c2..b45472b2c30 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs index 64a35aa824f..ecfeaceab67 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs @@ -420,6 +420,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs index 559e26cceb0..26358d2ca8e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs @@ -506,6 +506,12 @@ private void CheckValidInstance() public RequiredMetadataAndSpecVersionAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs index 2a12ffaf944..7ef929cfe42 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs @@ -291,6 +291,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs index 2c59a1739bd..af3ef1a3510 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs @@ -293,6 +293,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.Mutable.cs index 5083b365c9c..eafa5ce6dd8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.TypeEntity.cs index 3df279f5e4c..7859275310f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.TypeEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.cs index 2d1c2eded39..9ea1637632d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.cs @@ -363,6 +363,12 @@ private void CheckValidInstance() public WithTypeLibrary Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.cs index 33472cbd41f..79e7dc22cd0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.cs @@ -489,6 +489,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs index dd4210f4937..baeda11a30b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs @@ -823,6 +823,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index b0a08ec5d05..b2d0fe497ab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -823,6 +823,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs index fadacca3fce..27c882ee95e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs @@ -920,6 +920,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs index db455d83c81..4f7e7d217bd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs @@ -501,6 +501,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs index 189739592c5..a52fa5cf711 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs index c0a6bbd8fe2..50f110017ae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs index eac519f8e6d..e1c28da0620 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._aAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._aAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs index 1594e797e9b..a79eea025ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._aAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._aAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._cVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._cVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 03a805f41ca..70d0fcd8a16 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._cVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._cVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs index bf988a14840..3cfd64f8e19 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs index 9e44f34af05..13a0b082393 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs index 539db9668b4..40cfa2cb00d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs index 14616c04bd5..23854fd99a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs @@ -291,6 +291,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs index e18811c7996..dc2b47f2bba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs index 25837f4b06c..1f02cff98e6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs @@ -633,6 +633,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs index d0f610f8b63..7f52d4f1cef 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs index f5c88f45482..efc8e1901d0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.cs index 23b3b4f137a..b71fe1b828e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.cs index ff58e0d48d3..25b9d202006 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs index c00e980a04b..cda90f81e8d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs index a18cd48c298..4804ed325b7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs index 219277c0e8f..3661f13d695 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs @@ -896,6 +896,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index 50b6a18eddf..4e9ac334d76 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -704,6 +704,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs index 7290579ff2c..ffcf641c4a9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs @@ -825,6 +825,55 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs index 1d114c51bf7..7218f610656 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs @@ -293,6 +293,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._redMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._redMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs index f0ea665e340..59f03c134d6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._redMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._redMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs @@ -536,6 +536,43 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs index 6ae3d78834f..8790672a4cd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs index d06d4fb1dce..55f362e4d7b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs index e288656bf31..28b4ff24250 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs @@ -375,6 +375,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs index 14396dffda5..a4543d5aeaa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs @@ -453,6 +453,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs index 3c51016bc83..1b998862f3d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs index f0e20a805fe..96850aeda65 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs index b1bd925fcef..9e46fe21c6b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs index 6160adba9d7..778f2f6c3bd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs index 0e08d39922a..faf99901864 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity1.cs index 576accc9107..ff7e33d7fde 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity1.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable1.cs index 16c59f359af..703be404add 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable1.cs @@ -993,6 +993,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable1.cs index a0657e47e33..833991f7453 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable1.cs @@ -920,6 +920,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs index b1b9bd19e96..52de0e34795 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity1.cs index 9b6dbbf68b9..f8d3e4ae35b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity1.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity1.cs index 127397b3f75..bd5070048bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity1.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity1.cs index 2d760757ccc..d97744527f2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity1.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs index a915852e448..d3d67b06dad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs index b5a6438716e..d758a7277ee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs index 79131aa30e7..b575bba6e14 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs @@ -252,6 +252,31 @@ public bool RemovePaths() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Mutable.cs index 8524f62ca92..28f3113e9a8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Mutable.cs @@ -981,6 +981,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs index 7be82763c0d..3a2fee497be 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs index 4419eb91def..5da60c473c4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 327e5779ce6..38f1deb671a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs index 6a5cfd56699..39abc7ccd11 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs index ea7a41b8131..6f494ce5737 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs index 30ef71e1404..c6368fa64d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTyp_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTyp_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs index 230f053d234..bbc47a81768 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTyp_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTyp_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.Mutable.cs index 3917e84f846..3e226cf3502 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemoveSignatureType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.SignatureTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.SignatureTypeEntity.cs index 68714808358..1b4adee961e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.SignatureTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.SignatureTypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SignatureTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.cs index dc74c28f656..4551882ffd1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public CachebusterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs index a4c4d9cfb5d..65441965848 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs @@ -632,6 +632,49 @@ public bool RemoveResources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CachebusterUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.Mutable __corvusCachebuster)) + { + __corvusCachebuster.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadEntity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs index ef6dfe528ac..6d20f7b8ab4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs @@ -354,6 +354,12 @@ private void CheckValidInstance() public BuilderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.Mutable.cs index 4e0bbb61d52..53ec9909022 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemoveSignatureType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.cs index 7441ac231fb..7e8f7b877cf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public CachebusterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs index bfe8009da34..7b9f3f1e168 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs @@ -632,6 +632,49 @@ public bool RemoveResources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CachebusterUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.Mutable __corvusCachebuster)) + { + __corvusCachebuster.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs index a34929d9c9c..1198e47e947 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs @@ -354,6 +354,12 @@ private void CheckValidInstance() public BuilderSpecVersion23Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.Mutable.cs index eaba465448f..6aecf437c01 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemoveSignatureType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.cs index f89eea28d9a..29d8bbadc40 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public CachebusterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs index fd9c6938e7c..afd4d9c3824 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs @@ -632,6 +632,49 @@ public bool RemoveResources() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CachebusterUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.Mutable __corvusCachebuster)) + { + __corvusCachebuster.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs index 2aeb2c9628c..9bd0c7d7e40 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs @@ -354,6 +354,12 @@ private void CheckValidInstance() public BuilderSpecVersion24Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.Mutable.cs index 45de356a387..9f062662ba9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemoveSignatureType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.cs index eae5df39c9b..46e35ab0af1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public CachebusterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs index 72330c2fde1..e27340c48ea 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs @@ -729,6 +729,55 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CachebusterUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.Mutable __corvusCachebuster)) + { + __corvusCachebuster.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs index 28c10df5ca5..1ebcc0c7495 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public BuilderSpecVersion25Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.Mutable.cs index b3777502d50..9465d0071d2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemoveSignatureType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.cs index 2277e771afa..4f096f1b8fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public CachebusterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs index 28abd9da44f..858ace9502f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs @@ -826,6 +826,61 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CachebusterUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.Mutable __corvusCachebuster)) + { + __corvusCachebuster.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinificationUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable __corvusMinification)) + { + __corvusMinification.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs index f38307835c1..47fb9decf7b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public BuilderSpecVersion26Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.Mutable.cs index 7bf90f4d3c6..83794126e55 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemoveSignatureType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.cs index 5afcd001e3e..6df635639d3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public CachebusterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs index 83ff0e7b18f..2e26f528ce8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs @@ -826,6 +826,61 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CachebusterUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.Mutable __corvusCachebuster)) + { + __corvusCachebuster.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentPreloadUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderComponentPreloadSpecVersion23Entity.Mutable __corvusComponentPreload)) + { + __corvusComponentPreload.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinificationUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderMinificationEntity.Mutable __corvusMinification)) + { + __corvusMinification.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.BuilderSettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs index d5ad0119919..1682486529b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public BuilderSpecVersion30Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs index 4b2c249ccf0..6b5b04833aa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs @@ -499,6 +499,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs index 2036e61aaa1..edaf57b02b0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs @@ -289,6 +289,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs index d91842bdfa8..c6ab407fb4a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs index 3ee1c50500a..917715793ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs @@ -991,6 +991,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs index 87ef719b879..a7d82a9f922 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs index 84c2eb01a17..eca0faac8aa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs @@ -497,6 +497,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs index b557fdf36c8..3f056a37f75 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs index 61a08276428..c2e7c335bd0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs index cea41416d45..649e4358e3d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index 51da41f303c..467ac6b5fad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -989,6 +989,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs index 06a528f0994..8c8b6e10e7b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs index 722f4087d0d..522bd7ba740 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs @@ -918,6 +918,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs index d4af92725f9..b1eaab7ec8c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs index a0661cefff7..931a6502afc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs index b5000ce537d..07b74025218 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs index b19b6cb8066..1a229282c05 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs @@ -495,6 +495,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs index 88640ff221b..9b21b317c8b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs @@ -285,6 +285,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs index c139b9a33b0..2049d084745 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs index 6fbac721e54..08ff05fb242 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs index 48284df3563..9823e6ba245 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs @@ -987,6 +987,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs index 817381cff00..641b7849973 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs @@ -353,6 +353,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs index bb60b24f4f8..b6185b100a1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs index 4f7fa53f669..a45fa4e7551 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs @@ -916,6 +916,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs index b19408012cf..9341e078a3f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs index bf137d44fd2..96ae0ea520b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs index 54b3f617677..9f0ee5a297e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs index ada518387ea..d8f0c9527cc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs index b5a57c769ea..d6080161cbe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs @@ -283,6 +283,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs index d4b92e476df..d8b4571684c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs index 396d7d608b8..4eca5ebc9ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs index 007a7f753a1..6c4f7660792 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs @@ -985,6 +985,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 96861256aa8..cc88d3d5484 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -351,6 +351,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs index a6320bd22dd..4fd0e473e36 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs index b003d09b156..e5296fe8a31 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs @@ -914,6 +914,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs index 214a3bd52d7..a7f64313faa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs index f17be08fa3e..1fd6e05df83 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs index 5a18c20f753..1a45a33af33 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs @@ -420,6 +420,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs index edd1bde0278..413760370fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs @@ -491,6 +491,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs index f191a4468da..15031751f16 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.Mutable.cs @@ -281,6 +281,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs index 48c9fa40423..4b9500c0289 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs index c43e2d962c2..ac4909c6da9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs @@ -363,6 +363,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs index 9c988b0c09b..b191149c5ea 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs @@ -954,6 +954,61 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs index 6f5845a8a84..c769b849eac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs @@ -312,6 +312,42 @@ public bool RemovePropertiesFileSourceEncoding() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropertiesFileSourceEncodingUtf8, out IJsonDocument? _, out int _)) + { + SetPropertiesFileSourceEncoding(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PathsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable __corvusPaths)) + { + __corvusPaths.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable.cs index 2405d251227..d421f66d53e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable.cs @@ -212,6 +212,31 @@ public bool RemoveWebapp() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs index b6320bff6ae..4213541a69c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs @@ -294,6 +294,12 @@ private void CheckValidInstance() public PathsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs index 2007939c485..e6b1bce7f26 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs index 00062af372b..2f910584c47 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs @@ -244,6 +244,37 @@ public bool RemoveConfiguration() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigurationUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable __corvusConfiguration)) + { + __corvusConfiguration.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs index 3934b75ae70..0328c6296c6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs @@ -290,6 +290,12 @@ private void CheckValidInstance() public ResourcesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs index f5d9e62fce3..9a0447977fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs index 39ca0cdc149..d2d5734a73f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs index cd603792051..73c2df43f25 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs @@ -912,6 +912,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs index 67b30e35a32..c17650c91f9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs index 058ed9a7b85..6bb4bc2e32f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs index 64e534a6e3b..6d6c67ed8d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs index d0b691508ce..34248f1e84d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs @@ -504,6 +504,12 @@ private void CheckValidInstance() public RequiredMetadataAndSpecVersionAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs index dcec0321881..ea04a76110e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs index e5274e4253e..bee8015da9b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs @@ -993,6 +993,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs index 077bda6401b..ea87036b55e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs @@ -920,6 +920,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs index 707a84de0bd..57dc1f73f61 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs @@ -922,6 +922,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs index 62cf662254d..d81968d47ed 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs index b61e7f19ddd..7dc3b52918e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs index de666c18b98..938795448cb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs @@ -331,6 +331,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs index 355e4aa266e..3f79dc61f28 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs index 57b416791b1..7ff624c403c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs index 2f9e7628fee..f9b586f1188 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs index ccdf2cadd16..e20e117c987 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs @@ -825,6 +825,61 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs index bbd937d43e8..b3c55c7cf6b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs @@ -291,6 +291,31 @@ public bool RemoveSpecVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs index 9311406cacd..fd64791b76e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ElseEntity2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs index c0af7a6c4d0..c53f5554b2a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs index 15c233a63d9..78b0ad3706e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.Mutable.cs index 9c3a997aeb9..d64394d51ca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.Mutable.cs @@ -279,6 +279,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.TypeEntity.cs index d6cd79a362e..9ad9ece6c51 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.TypeEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.cs index a8fef51f68a..e7f3fe06294 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public WithTypeApplication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.cs index b5af25e4f60..9c1f420a490 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.cs @@ -487,6 +487,12 @@ private void CheckValidInstance() public ElseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs index 9f414184084..4c59a3cae36 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs index 27bfd1c4233..d7390059244 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs index f71c0219f4e..8d418aecc80 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public PathsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs index 3a91aaf3b9a..8f8e7ce9e37 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity1.cs index 680e18db61b..bace5cb8124 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity1.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity2.cs index 91a1f098fcf..93104f736a8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity2.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public CustomConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.cs index 59e348212f8..eba0f4a99c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public EncodingOfPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.KindEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.KindEntity.cs index a985e069e71..e083e52fc6b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.KindEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.KindEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public KindEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.Mutable.cs index b2664c1ef79..00b97799e3d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.Mutable.cs @@ -961,6 +961,61 @@ public void SetType(scoped in Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpec _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuilderValueUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable __corvusBuilderValue)) + { + __corvusBuilderValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FrameworkUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable __corvusFramework)) + { + __corvusFramework.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MetadataUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable __corvusMetadata)) + { + __corvusMetadata.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServerUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable __corvusServer)) + { + __corvusServer.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.AllowSapInternalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.AllowSapInternalEntity.cs index 3fe48c5f2ae..1aa2cbaf040 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.AllowSapInternalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.AllowSapInternalEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AllowSapInternalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.DeprecatedEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.DeprecatedEntity.cs index cc2c06dba0f..e68d2070ef8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.DeprecatedEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.DeprecatedEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DeprecatedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable.cs index 537d9e5b938..1b9cb15c22a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.Mutable.cs @@ -439,6 +439,46 @@ public bool RemoveSapInternal() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowSapInternalUtf8, out IJsonDocument? _, out int _)) + { + SetAllowSapInternal(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.AllowSapInternalEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeprecatedUtf8, out IJsonDocument? _, out int _)) + { + SetDeprecated(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.DeprecatedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapInternalUtf8, out IJsonDocument? _, out int _)) + { + SetSapInternal(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.SapInternalEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.SapInternalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.SapInternalEntity.cs index 6747d050435..0217fcfb899 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.SapInternalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.SapInternalEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public SapInternalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.cs index c397f88a798..c25b3d1af6e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.cs index eecb123f409..850c003fe24 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AllowSapInternalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.DeprecatedEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.DeprecatedEntity.cs index bb59a5e9469..08715742521 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.DeprecatedEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.DeprecatedEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DeprecatedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable.cs index 9b701426d95..d27d94257da 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.Mutable.cs @@ -443,6 +443,46 @@ public bool RemoveSapInternal() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowSapInternalUtf8, out IJsonDocument? _, out int _)) + { + SetAllowSapInternal(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeprecatedUtf8, out IJsonDocument? _, out int _)) + { + SetDeprecated(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.DeprecatedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapInternalUtf8, out IJsonDocument? _, out int _)) + { + SetSapInternal(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.SapInternalEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.ProjectName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.ProjectName.cs index 30c6dec56c7..2c7543c1234 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.ProjectName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.ProjectName.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public ProjectName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.SapInternalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.SapInternalEntity.cs index 9c21fc562f8..8e205a35d34 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.SapInternalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.SapInternalEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public SapInternalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.cs index a4ca6d8f164..d1a655a8d40 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public RequiredSpecVersionAndTypeRequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable.cs index 50df6b67e19..80e958da375 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Mutable.cs @@ -359,6 +359,31 @@ public bool RemoveVersionValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.NameEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.NameEntity.cs index 4b6016b4f9c..05e3fb14d44 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.NameEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.NameEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public NameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Requir_._RequiredName.IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Requir_._RequiredName.IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.cs index 870dc3f1199..f89e9cd4182 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Requir_._RequiredName.IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Requir_._RequiredName.IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DevelopmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredN_._RequiredName.IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredN_._RequiredName.IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.cs index f99dffbd579..ffae26111b0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredN_._RequiredName.IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredN_._RequiredName.IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OptionalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf2Entity.NotEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf2Entity.NotEntity.cs index 8dc44ff7c92..5581c40f2fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf2Entity.NotEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf2Entity.NotEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public NotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf3Entity.NotEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf3Entity.NotEntity.cs index 7fa44c7268e..02220a4e0f4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf3Entity.NotEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf3Entity.NotEntity.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public NotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.DevelopmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.DevelopmentEntity.cs index 3938ab4d4fc..c455817e0dc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.DevelopmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.DevelopmentEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DevelopmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.Mutable.cs index 471230d51cb..a10d7137472 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveOptional() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.cs index 9d6a5b23eea..0d655932556 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.Mutable.cs index 5226ff51326..bec9b8a9a5e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.Mutable.cs @@ -287,6 +287,31 @@ public bool RemoveDevelopment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.cs index 5aea8ca4fc8..48e7a921cd9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.cs index 47baf1ab9f7..a7caf5467ca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.cs @@ -469,6 +469,12 @@ private void CheckValidInstance() public AnyOf2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.cs index e2124169ded..7da5051bd64 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.cs @@ -469,6 +469,12 @@ private void CheckValidInstance() public AnyOf3Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.cs index 24e6618716e..b2b3d570443 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.cs @@ -459,6 +459,12 @@ private void CheckValidInstance() public NotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.cs index 8b3963b8954..6265cc458ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.cs @@ -465,6 +465,12 @@ private void CheckValidInstance() public IfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.Mutable.cs index 509c5df5354..192c91b9678 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.Mutable.cs @@ -321,6 +321,41 @@ public bool RemoveOptional() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DevelopmentUtf8, out IJsonDocument? _, out int _)) + { + SetDevelopment(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.DevelopmentEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionalUtf8, out IJsonDocument? _, out int _)) + { + SetOptional(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.OptionalEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.OptionalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.OptionalEntity.cs index aece3458df2..12721fb9ca2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.OptionalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.OptionalEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public OptionalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.Mutable.cs index acda062f663..85f960fd5de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.Mutable.cs @@ -210,6 +210,31 @@ public bool RemoveName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.cs index cce756cf749..c4fe11aec10 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.cs index e708b502e8f..cffeb7d7349 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.cs index 4e5e7582e70..7f84758f000 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredSpecVersionAndTypeRequiredName1 public readonly partial struct RequiredNameArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public RequiredNameArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf2Entity.NotEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf2Entity.NotEntity.Mutable.cs index 2a26b41fd70..576fe0530fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf2Entity.NotEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf2Entity.NotEntity.Mutable.cs @@ -289,6 +289,31 @@ public bool RemoveOptional() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf3Entity.NotEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf3Entity.NotEntity.Mutable.cs index 3c963c0ce82..d0497d06a4e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf3Entity.NotEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf3Entity.NotEntity.Mutable.cs @@ -289,6 +289,31 @@ public bool RemoveDevelopment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Version.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Version.cs index 768cf85f555..2471c6509c6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Version.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Version.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public Version Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.cs index ef717e9d302..03f9f8d9c52 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public RequiredSpecVersionAndTypeRequiredName1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.JsonStringArray.cs index 6ca823b9cbe..7b4438c9504 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredSpecVersionAndTypeRequiredName2 public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.Mutable.cs index b4976abeb67..67980f036d5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.Mutable.cs @@ -389,6 +389,31 @@ public bool RemoveSections() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs index 615121bf57d..7c7da14579c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct RequiredFiltersAndMode public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs index d114eac0609..d8131249609 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public ModeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs index ed883edd304..2cca3fd887e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs @@ -651,6 +651,56 @@ public bool RemoveSort() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeclareRawModulesUtf8, out IJsonDocument? _, out int _)) + { + SetDeclareRawModules(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RendererUtf8, out IJsonDocument? _, out int _)) + { + SetRenderer(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResolveUtf8, out IJsonDocument? _, out int _)) + { + SetResolve(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResolveConditionalUtf8, out IJsonDocument? _, out int _)) + { + SetResolveConditional(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SortUtf8, out IJsonDocument? _, out int _)) + { + SetSort(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs index ff1698dab2c..e856c610709 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public RendererEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs index f95bab2d1a6..dd9aa38edd8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ResolveEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs index 99935b9a375..379d2016c67 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public SortEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs index d903e6da0bf..bb7ba135976 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public RequiredFiltersAndMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.cs index d737887d3ee..1046384f4a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredSpecVersionAndTypeRequiredName2 public readonly partial struct RequiredFiltersAndModeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public RequiredFiltersAndModeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.cs index 7a4c798c60f..b1a4929790b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public RequiredSpecVersionAndTypeRequiredName2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.JsonStringArray.cs index dd5ec667652..581c2dd1eae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredSpecVersionAndTypeRequiredName3 public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.Mutable.cs index 6fd3ce09d1c..a976c9dfbd2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.Mutable.cs @@ -389,6 +389,31 @@ public bool RemoveSections() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs index 57fa54f83e5..37c6c618772 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs @@ -31,11 +31,13 @@ public readonly partial struct RequiredFiltersAndMode public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -85,6 +87,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -298,6 +315,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs index 7d99a002a4e..81fce523031 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public ModeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs index 72fe167de0a..874abd25cfc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs @@ -651,6 +651,56 @@ public bool RemoveSort() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeclareRawModulesUtf8, out IJsonDocument? _, out int _)) + { + SetDeclareRawModules(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RendererUtf8, out IJsonDocument? _, out int _)) + { + SetRenderer(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResolveUtf8, out IJsonDocument? _, out int _)) + { + SetResolve(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResolveConditionalUtf8, out IJsonDocument? _, out int _)) + { + SetResolveConditional(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SortUtf8, out IJsonDocument? _, out int _)) + { + SetSort(Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs index 7941dc93727..26fd9ba10fb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public RendererEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs index 195984a657c..a05c9a815c9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ResolveEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs index 6933d126efc..b4c4842f2b9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public SortEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs index b1e79b02b1f..d7971ff5340 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public RequiredFiltersAndMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.cs index bd10354c9f6..89fe2fcc28a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredSpecVersionAndTypeRequiredName3 public readonly partial struct RequiredFiltersAndModeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public RequiredFiltersAndModeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.cs index 9f06b714a4d..a33283a0f8b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public RequiredSpecVersionAndTypeRequiredName3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.Mutable.cs index 2331b291208..a40cc7e17a8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.Mutable.cs @@ -411,6 +411,31 @@ public void SetName(scoped in Corvus.Ui5Benchmark.Current.JsonString.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.cs index 677c1e232a2..f2f389b6b9f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public RequiredAfterMiddlewareAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.Mutable.cs index fd401866a81..611e574785f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.Mutable.cs @@ -411,6 +411,31 @@ public void SetName(scoped in Corvus.Ui5Benchmark.Current.JsonString.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.cs index aa32975d653..bd8bab44e70 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredBeforeMiddlewareAndName.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public RequiredBeforeMiddlewareAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.cs index b92b7c4c256..5f3004c8b5b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public CustomMiddlewareEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.cs index 155e5f7c093..cdf996cfbee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.cs @@ -27,11 +27,13 @@ public readonly partial struct ServerEntity public readonly partial struct CustomMiddlewareEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public CustomMiddlewareEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable.cs index 3c9513603d2..9797d3b2f80 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.Mutable.cs @@ -337,6 +337,37 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5Benchmark.Current.Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.Mutable.cs index 059518f8acb..fed255c7b32 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.Mutable.cs @@ -267,6 +267,31 @@ public bool RemoveHttpsPort() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.cs index 55617a1dc0a..0a692421ea2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.SettingsEntity.cs @@ -304,6 +304,12 @@ private void CheckValidInstance() public SettingsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.cs index f31984a69a0..6955ab6a964 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.cs @@ -302,6 +302,12 @@ private void CheckValidInstance() public ServerEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.SpecVersionEntity.cs index 6d13d294ecb..55cce3b516c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.SpecVersionEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.TypeEntity.cs index 147f5bfddf7..5d48c376133 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.TypeEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.Mutable.cs index 8b77c9334f1..bb44923df7c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.TypeEntity.cs index d2b9a9367e8..54aa89568a8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.TypeEntity.cs @@ -270,6 +270,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.cs index 4ae148e712b..09ff9d2d8f0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.cs index b173ddb543a..10e5728a6b9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.cs @@ -495,6 +495,12 @@ private void CheckValidInstance() public RequiredSpecVersionAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs index 6a0a77f2b7d..ff1ec983d9a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ResolveConditionalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs index 3cfa3bc4391..16b844b4fa6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ResolveConditionalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs index b8a4c5bb628..8b313fade18 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DeclareRawModulesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs index 365d3558d4a..cf5ba99612c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DeclareRawModulesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.SpecVersionEntity.cs index 2f15dfb20a4..ec94bd0ad34 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.SpecVersionEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.cs index 974ca2cbfad..16b7159d2dc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.RequiredSpecVersion.cs @@ -536,6 +536,12 @@ private void CheckValidInstance() public RequiredSpecVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.SpecVersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.SpecVersionEntity.cs index afa91f7908d..9ed194a7360 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.SpecVersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.SpecVersionEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SpecVersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.cs b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.cs index 4171d20f721..52ab1b5ba10 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.cs +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/Ui5Schema.cs @@ -538,6 +538,12 @@ private void CheckValidInstance() public Ui5Schema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/corvusjson-jsonschema.lock index 4ccdceb555c..384266f4bbf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.Ui5BenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:48.2032808\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:41.6112620\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { @@ -74,23 +74,25 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEnti_.__ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntit_._ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.E_._ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.El_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.El_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.El_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Els_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Els_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseE_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseE_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEn_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEn_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.E_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.E_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.E_._ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Els_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Els_._ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEn_._ElseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEnt_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEnt_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEnt_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.IfEntity.JsonSchema.cs", @@ -100,8 +102,11 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ElseEntity.cs", @@ -114,9 +119,13 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ShimsEntity.Mutable.cs", @@ -127,6 +136,7 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.ThenEntity2.TypeEntity.JsonSchema.cs", @@ -148,6 +158,7 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", @@ -168,6 +179,7 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", @@ -209,6 +221,9 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeServerMiddleware.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Else_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Else_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Else_._ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.JsonSchema.cs", @@ -281,33 +296,18 @@ "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.WithTypeTask.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._2.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity2.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity.ThenEntity.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity.ThenEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._lseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._lseEntity.ThenEntity.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._nEntity.ShimsEntity.CollectionsEntity.Entity.ModulesEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ShimsEntity.CollectionsEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ThenEntity2.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._tity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ty.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ty2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._y2.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ElseEntity.ThenEntity.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._Entity2.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._eEntity2.ElseEntity.ThenEntity.ShimsEntity.ConfigurationsEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ity2.ElseEntity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ity2.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ntity2.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._seEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._tity.ThenEntity.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._tity2.ElseEntity.ThenEntity.ShimsEntity.DependenciesEntity.JsonStringArray.cs", + "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.ElseEntity_._ty2.ElseEntity.ThenEntity.ThenEntity2.CustomConfigurationEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.KindEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.ElseEntity.RequiredKindAndMetadataAndSpecVersionAndType.KindEntity.Mutable.cs", @@ -464,44 +464,45 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.CustomTasksEntityArray.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEn_._RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.E_._RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.El_.__RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Els_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnt_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntit_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntit_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEnt_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Els_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Els_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseE_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseE_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseE_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseE_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseE_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEn_._RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnt_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnt_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnt_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEnti_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntit_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntit_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntit_._RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.E_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.El_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntit_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.JsonSchema.cs", @@ -514,8 +515,13 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs", @@ -534,11 +540,20 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.JsonSchema.cs", @@ -548,9 +563,13 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.cs", @@ -562,6 +581,7 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.JsonSchema.cs", @@ -583,82 +603,65 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.WithTypeThemeLibrary.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._AndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._AndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._Type.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._e.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._nAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._nAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._sionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._sionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ype.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ype.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Else_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._cVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._cVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._dType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._e.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._nAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._nAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._ndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._onAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._rsionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._rsionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity_._sionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Re_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Req_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Requ_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Requi_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Requir_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Require_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMeta_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMeta_.__ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetad_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetada_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetada_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetada_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadat_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadat_.__ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Require_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredM_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMet_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMeta_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadat_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadat_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataA_.__ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAn_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndS_.__ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSp_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecV_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecV_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVe_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVe_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVe_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVer_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVer_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVer_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVer_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersi_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersi_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs", @@ -683,11 +686,18 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", @@ -697,8 +707,13 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.cs", @@ -710,6 +725,7 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", @@ -734,6 +750,7 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.JsonSchema.cs", @@ -755,11 +772,28 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAnd_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAnd_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadata_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAndSpec_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAnd_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAnd_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadataAnd_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadata_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadata_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadata_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.RequiredMetadata_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Required_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Required_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.Required_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.TypeEntity.JsonSchema.cs", @@ -767,144 +801,106 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.WithTypeLibrary.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._SpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._aAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._adataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._adataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._cVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._cVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._redMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._redMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._adataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._adataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._ersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._taAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._taAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._tadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._Entity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._dMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._eEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._lseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._lseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._quiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._seEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._seEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._taAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity.RequiredMetadataAndSpecVersionAndType.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._tity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._ty2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._uiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._uiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._uiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._uiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._uiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2_._y2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._AndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._MetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._SpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._SpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._SpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._adataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._adataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._adataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._edMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._etadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._iredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.ElseEntity2__._redMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Else_.__RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.JsonSchema1.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVe_.__ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVe_.__ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVer_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVers_._ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVers_._ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersi_.__ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersi_.__ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndT_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_.__ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTyp_._ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionA_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAn_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAn_._ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAn_._ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndTy_._ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", @@ -916,39 +912,56 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.E_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.E_._ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.El_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", @@ -958,9 +971,13 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ElseEntity.cs", @@ -972,6 +989,7 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.IfEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", @@ -1043,55 +1061,49 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._eEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._eEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._tity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._tity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._y2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ty.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ty.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAnd_.__ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersion_._ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersion_._ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._Entity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._eEntity.ElseEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._eEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._eEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._eEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._eEntity2.ElseEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity.ElseEntity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ity2.ElseEntity.ElseEntity2.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._lseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._lseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity.ElseEntity2.ElseEntity.ElseEntity2.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity.ElseEntity2.ElseEntity.ElseEntity2.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.KindEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.TypeEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ThenEntity.KindEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._seEntity2.ElseEntity.ElseEntity2.ThenEntity.TypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._tity.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._tity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._tity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._ty.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._y.ElseEntity2.ElseEntity.ElseEntity2.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._y.ElseEntity2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._y2.ElseEntity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType_._y2.ElseEntity.ElseEntity2.ThenEntity.SpecVersionEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ity.ElseEntity2.ElseEntity.ThenEntity.SpecVersionEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ntity.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAndType__._ty.ElseEntity2.ElseEntity.IfEntity.SpecVersionEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersionAnd_.__ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersion_.__ElseEntity.ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersion_.__ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.RequiredMetadataAndSpecVersion_.__ElseEntity2.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.TypeEntity.JsonSchema.cs", @@ -1099,28 +1111,16 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.WithTypeApplication.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.BuilderSpecVersion31Entity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity.ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._ElseEntity2.RequiredMetadataAndSpecVersionAndType.ThenEntity.CustomConfigurationEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._RequiredMetadataAndSpecVersionAndType.ElseEntity.ElseEntity2.ThenEntity.CustomConfigurationEntity2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_.__RequiredMetadataAndSpecVersionAndType.ElseEntity.ThenEntity.CustomConfigurationEntity.JsonSchema2.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_.__RequiredMetadataAndSpecVersionAndType.ResourcesEntity.ConfigurationEntity.PathsEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._aAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._aAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._aAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._aAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._aAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dMetadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dMetadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dMetadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dMetadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._dMetadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._tadataAndSpecVersionAndType.BuilderSpecVersion23Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._tadataAndSpecVersionAndType.BuilderSpecVersion24Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._tadataAndSpecVersionAndType.BuilderSpecVersion25Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._tadataAndSpecVersionAndType.BuilderSpecVersion26Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ElseEntity_._tadataAndSpecVersionAndType.BuilderSpecVersion30Entity.CachebusterEntity.SignatureTypeEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.EncodingOfPropertiesFiles.cs", @@ -1141,24 +1141,14 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.SapInternalEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.SapInternalEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredName.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionA_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAn_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndT_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndT_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTy_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTyp_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeReq_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequ_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequi_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequi_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequir_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequir_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequire_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequire_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredN_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredNa_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredNa_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredNa_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTyp_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeR_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRe_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRe_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeReq_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.Mutable1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequ_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequi_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredNa_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName.AllowSapInternalEntity.cs", @@ -1179,19 +1169,11 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.NameEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.NameEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.NameEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Requir_._RequiredName.IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredN_._RequiredName.IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNam_._IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNam_._IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameA_._RequiredName.IfEntity.NotEntity.AnyOf0Entity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameA_._RequiredName.IfEntity.NotEntity.AnyOf1Entity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameA_._RequiredName.IfEntity.NotEntity.AnyOf2Entity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameA_._RequiredName.IfEntity.NotEntity.AnyOf3Entity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf2Entity.NotEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf3Entity.NotEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArra_._IfEntity.NotEntity.AnyOf2Entity.NotEntity.JsonSchema.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArra_._IfEntity.NotEntity.AnyOf3Entity.NotEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNam_._RequiredName.IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameA_._IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameAr_._RequiredName.IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArra_._IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArra_._IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.DevelopmentEntity.JsonSchema.cs", @@ -1199,13 +1181,19 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.DevelopmentEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf0Entity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf1Entity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.NotEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf2Entity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.NotEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.AnyOf3Entity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.IfEntity.NotEntity.Mutable.cs", @@ -1221,9 +1209,11 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.ThenEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.RequiredName.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf2Entity.NotEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf3Entity.NotEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Required_._IfEntity.NotEntity.AnyOf1Entity.DevelopmentEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._ame.IfEntity.NotEntity.AnyOf2Entity.NotEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._ame.IfEntity.NotEntity.AnyOf3Entity.NotEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._e.IfEntity.NotEntity.AnyOf0Entity.OptionalEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._edName.IfEntity.NotEntity.AnyOf2Entity.NotEntity.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.RequiredNameArray_._edName.IfEntity.NotEntity.AnyOf3Entity.NotEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Version.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Version.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName1.Version.cs", @@ -1235,13 +1225,22 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs", @@ -1254,24 +1253,29 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.Mutable.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.RendererEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequiredName3.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequired_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequired_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.ModeEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequired_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveEntity.Mutable1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequired_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.SortEntity.JsonSchema1.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndType_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.Mutable.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAnd_._RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.JsonSchema.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndTypeRequired_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.JsonStringArray.JsonSchema1.cs", + "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.RequiredSpecVersionAndType_.__RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.JsonSchema1.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.ServerEntity.CustomMiddlewareEntityArray.CustomMiddlewareEntity.RequiredAfterMiddlewareAndName.JsonSchema.cs", @@ -1303,10 +1307,6 @@ "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.TypeEntity.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.WithTypeNull.cs", "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._edSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.ResolveConditionalEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName2.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs", - "Ui5Schema.RequiredSpecVersion.RequiredSpecVersionAndType_._redSpecVersionAndTypeRequiredName3.RequiredFiltersAndModeArray.RequiredFiltersAndMode.DeclareRawModulesEntity.cs", "Ui5Schema.RequiredSpecVersion.SpecVersionEntity.JsonSchema.cs", "Ui5Schema.RequiredSpecVersion.SpecVersionEntity.Mutable.cs", "Ui5Schema.RequiredSpecVersion.SpecVersionEntity.cs", diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.DataEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.DataEntity.cs index bb05c625f89..80918250c0e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.DataEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.DataEntity.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public DataEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.MustBeActionExecute.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.MustBeActionExecute.cs index f9dd6bb5125..18fd57d6a98 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.MustBeActionExecute.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.MustBeActionExecute.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeActionExecute Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.Mutable.cs index 5e3a1fde2ef..b356dfc2afc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.Mutable.cs @@ -1345,6 +1345,31 @@ public bool RemoveVerb() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.cs index bd2b1a1b7dd..eef7e04146d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionExecute.cs @@ -532,6 +532,12 @@ private void CheckValidInstance() public ActionExecute Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf0Entity.cs index 2406b5f5c37..344837497d0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf1Entity.cs index ad844f97278..64edae5bda7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.cs index 46c63f00487..207f8c2bcec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionMode.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ActionMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.MustBeActionOpenUrl.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.MustBeActionOpenUrl.cs index fdeeaff579d..646b15540e0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.MustBeActionOpenUrl.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.MustBeActionOpenUrl.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeActionOpenUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.Mutable.cs index 7487f1200d0..5a3e39d97dc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.Mutable.cs @@ -1166,6 +1166,31 @@ public void SetUrl(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonUriReferenc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.cs index a45c6cd8b03..b282ab203f6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionOpenUrl.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ActionOpenUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.ImplementationsOfActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.ImplementationsOfActionArray.cs index b4db4ed0be1..6cc72bc6b37 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.ImplementationsOfActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.ImplementationsOfActionArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ActionSet public readonly partial struct ImplementationsOfActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImplementationsOfActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.MustBeActionSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.MustBeActionSet.cs index 03d0be322ce..21da9050ec0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.MustBeActionSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.MustBeActionSet.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeActionSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.Mutable.cs index 0a4bdcb0aa4..a784490f317 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.Mutable.cs @@ -1024,6 +1024,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.cs index 074d1982d94..38454947a0a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSet.cs @@ -479,6 +479,12 @@ private void CheckValidInstance() public ActionSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.MustBeActionShowCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.MustBeActionShowCard.cs index e0505d9d57d..9e07e3dfb0c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.MustBeActionShowCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.MustBeActionShowCard.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeActionShowCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.Mutable.cs index f8c78fe5515..1652b4ac2e4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.Mutable.cs @@ -1216,6 +1216,37 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CardUtf8, out Corvus.Ui5ManifestBenchmark.Current.AdaptiveCard.Mutable __corvusCard)) + { + __corvusCard.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.cs index 39d093b2e12..751b7275109 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionShowCard.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ActionShowCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf0Entity.cs index 045c79dcd99..b7fee681a70 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf1Entity.cs index 256064ee920..4bdcdc6353d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.cs index 2f51cbfd1b9..fa751b93626 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionStyle.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ActionStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.DataEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.DataEntity.cs index c1e6591e737..14484b5586f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.DataEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.DataEntity.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public DataEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.MustBeActionSubmit.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.MustBeActionSubmit.cs index 8acdf2f4e2f..8ec6d09963b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.MustBeActionSubmit.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.MustBeActionSubmit.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeActionSubmit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.Mutable.cs index ad50fb6e56d..52e826829ca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.Mutable.cs @@ -1279,6 +1279,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.cs index dbf9444ea8b..6dcb48bb07d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionSubmit.cs @@ -511,6 +511,12 @@ private void CheckValidInstance() public ActionSubmit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.MustBeActionToggleVisibility.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.MustBeActionToggleVisibility.cs index 47e5198a8b2..481a3851496 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.MustBeActionToggleVisibility.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.MustBeActionToggleVisibility.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeActionToggleVisibility Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.Mutable.cs index 949903bc64e..4aa71088e7b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.Mutable.cs @@ -1200,6 +1200,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.TargetElementArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.TargetElementArray.cs index 163e10dd078..55774cf1357 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.TargetElementArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.TargetElementArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ActionToggleVisibility public readonly partial struct TargetElementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TargetElementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.cs index f9e8f6b96be..6c6ef7cb015 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ActionToggleVisibility.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ActionToggleVisibility Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfActionArray.cs index 4d8f732660e..0c5aa43a1cb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfActionArray.cs @@ -26,11 +26,13 @@ public readonly partial struct AdaptiveCard public readonly partial struct ImplementationsOfActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImplementationsOfActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfElementArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfElementArray.cs index a0fc5be55bc..b97c6e44e90 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfElementArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.ImplementationsOfElementArray.cs @@ -26,11 +26,13 @@ public readonly partial struct AdaptiveCard public readonly partial struct ImplementationsOfElementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImplementationsOfElementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.MustBeAdaptiveCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.MustBeAdaptiveCard.cs index a26edbb0a98..2c61f331186 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.MustBeAdaptiveCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.MustBeAdaptiveCard.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeAdaptiveCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.Mutable.cs index 3c37bfb1923..8909c9e1aa4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.Mutable.cs @@ -1348,6 +1348,43 @@ public bool RemoveVerticalContentAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AuthenticationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Authentication.Mutable __corvusAuthentication)) + { + __corvusAuthentication.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RefreshUtf8, out Corvus.Ui5ManifestBenchmark.Current.Refresh.Mutable __corvusRefresh)) + { + __corvusRefresh.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.RtlEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.RtlEntity.cs index 68758e2b110..02106da2510 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.RtlEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.RtlEntity.cs @@ -306,6 +306,12 @@ private void CheckValidInstance() public RtlEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.SpecifiesTheBackgroundImageOfTheCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.SpecifiesTheBackgroundImageOfTheCard.cs index 4ef2fd90635..c2dfd9da968 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.SpecifiesTheBackgroundImageOfTheCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.SpecifiesTheBackgroundImageOfTheCard.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public SpecifiesTheBackgroundImageOfTheCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.cs index f6c741a9089..92767671232 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AdaptiveCard.cs @@ -589,6 +589,12 @@ private void CheckValidInstance() public AdaptiveCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf0Entity.cs index d2608adcd9f..440cc3e9611 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf1Entity.cs index c430c03f0bb..e0a8f7cd146 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.cs index aaa8c62adcd..a2e47b60f2e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AssociatedInputs.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public AssociatedInputs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.Mutable.cs index e2c6464f64e..3a33d350ae5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.Mutable.cs @@ -378,6 +378,31 @@ public void SetValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.cs index e341273ce9c..5af96f807fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/AuthCardButton.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public AuthCardButton Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.AuthCardButtonArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.AuthCardButtonArray.cs index fb4e0ed55bd..42ae682d181 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.AuthCardButtonArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.AuthCardButtonArray.cs @@ -26,11 +26,13 @@ public readonly partial struct Authentication public readonly partial struct AuthCardButtonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public AuthCardButtonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.MustBeAuthentication.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.MustBeAuthentication.cs index 224647a5a7d..01e3f22b7d7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.MustBeAuthentication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.MustBeAuthentication.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeAuthentication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.Mutable.cs index 942b1f480df..10ded2a3c28 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.Mutable.cs @@ -541,6 +541,37 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TokenExchangeResourceUtf8, out Corvus.Ui5ManifestBenchmark.Current.TokenExchangeResource.Mutable __corvusTokenExchangeResource)) + { + __corvusTokenExchangeResource.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.cs index 7e556a4b7b1..0f060dd1e22 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Authentication.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public Authentication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.MustBeBackgroundImage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.MustBeBackgroundImage.cs index d292090affe..26de83e8cd8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.MustBeBackgroundImage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.MustBeBackgroundImage.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeBackgroundImage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.Mutable.cs index c12a9a65212..b8053fd3f2f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.Mutable.cs @@ -458,6 +458,31 @@ public bool RemoveVerticalAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.cs index 1f29231f413..33aac4c2dcf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BackgroundImage.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public BackgroundImage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf0Entity.cs index 21e67def9ee..08e738b16a9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf1Entity.cs index 1d4d0818d7b..a730f1491df 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.cs index 22875f7a215..5aa3f003f23 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/BlockElementHeight.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public BlockElementHeight Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf0Entity.cs index f1c9119c040..646de1557ee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf1Entity.cs index 499b54ce15c..6c8e06b0aab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.cs index 5971582eff3..777d4ceb1a6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ChoiceInputStyle.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ChoiceInputStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf0Entity.cs index 75cd16fc8a4..d6607dc47a1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf1Entity.cs index 4134caf51ac..bdd94a40104 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.cs index da6666babbf..6c586b25312 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Colors.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public Colors Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.BackgroundImageEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.BackgroundImageEntity.cs index 0a965afda40..2ba39fe4a36 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.BackgroundImageEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.BackgroundImageEntity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public BackgroundImageEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.FallbackEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.FallbackEntity.cs index 82824eae771..2c3ae463474 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.FallbackEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.FallbackEntity.cs @@ -542,6 +542,12 @@ private void CheckValidInstance() public FallbackEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.ImplementationsOfElementArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.ImplementationsOfElementArray.cs index f47e00f9f08..12b7764855f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.ImplementationsOfElementArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.ImplementationsOfElementArray.cs @@ -26,11 +26,13 @@ public readonly partial struct Column public readonly partial struct ImplementationsOfElementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImplementationsOfElementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.MustBeColumn.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.MustBeColumn.cs index 3db451f5b00..42806c623bb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.MustBeColumn.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.MustBeColumn.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeColumn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.Mutable.cs index dba1d488ab1..4daa171e146 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.Mutable.cs @@ -1468,6 +1468,31 @@ public bool RemoveWidth() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.RtlEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.RtlEntity.cs index 3124278e0bf..c86363d1cce 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.RtlEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.RtlEntity.cs @@ -306,6 +306,12 @@ private void CheckValidInstance() public RtlEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.StyleHintForColumn.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.StyleHintForColumn.cs index 17d997fd8e1..de7fc0294ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.StyleHintForColumn.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.StyleHintForColumn.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public StyleHintForColumn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.VerticalContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.VerticalContentAlignmentEntity.cs index dc610d37f1d..f7e0c3ef822 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.VerticalContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.VerticalContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public VerticalContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.WidthEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.WidthEntity.cs index 1f874ddf2f7..7fb9c7f2a4a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.WidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.WidthEntity.cs @@ -456,6 +456,12 @@ private void CheckValidInstance() public WidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.cs index 023aebfbbbf..bedfb9c5b99 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Column.cs @@ -628,6 +628,12 @@ private void CheckValidInstance() public Column Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.ColumnArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.ColumnArray.cs index ecfe692c7f3..09ea559cd7a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.ColumnArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.ColumnArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ColumnSet public readonly partial struct ColumnArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ColumnArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.HorizontalAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.HorizontalAlignmentEntity.cs index 6c301eb1542..a6ff7e7ced0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.HorizontalAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.HorizontalAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HorizontalAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.MustBeColumnSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.MustBeColumnSet.cs index dade93a8d3a..efb56aa7a54 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.MustBeColumnSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.MustBeColumnSet.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeColumnSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.Mutable.cs index b42b98ce565..bd3935ace20 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.Mutable.cs @@ -1403,6 +1403,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.StyleHintForColumnSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.StyleHintForColumnSet.cs index e5a0fcaca77..54575659c0e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.StyleHintForColumnSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.StyleHintForColumnSet.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public StyleHintForColumnSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.cs index 5871958cc8c..08ceabc8c4b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ColumnSet.cs @@ -581,6 +581,12 @@ private void CheckValidInstance() public ColumnSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.BackgroundImageEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.BackgroundImageEntity.cs index 99fb5a92592..9adeda0a861 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.BackgroundImageEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.BackgroundImageEntity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public BackgroundImageEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.ImplementationsOfElementArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.ImplementationsOfElementArray.cs index 39e7b2f46e2..e8a2a0a9d2f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.ImplementationsOfElementArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.ImplementationsOfElementArray.cs @@ -26,11 +26,13 @@ public readonly partial struct Container public readonly partial struct ImplementationsOfElementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImplementationsOfElementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.MustBeContainer.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.MustBeContainer.cs index bb7f9a53326..56fd2ad796d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.MustBeContainer.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.MustBeContainer.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeContainer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.Mutable.cs index 2695a596707..e4663876038 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.Mutable.cs @@ -1558,6 +1558,31 @@ public bool RemoveVerticalContentAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.RtlEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.RtlEntity.cs index f569a52bfbd..8e48515f256 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.RtlEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.RtlEntity.cs @@ -306,6 +306,12 @@ private void CheckValidInstance() public RtlEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.StyleHintForContainer.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.StyleHintForContainer.cs index 3408b6fa784..ffcfe1e4997 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.StyleHintForContainer.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.StyleHintForContainer.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public StyleHintForContainer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.VerticalContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.VerticalContentAlignmentEntity.cs index 982b67c8fdd..a497ed42c4a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.VerticalContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.VerticalContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public VerticalContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.cs index 2ccafecd26f..b53452b0c66 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Container.cs @@ -626,6 +626,12 @@ private void CheckValidInstance() public Container Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf0Entity.cs index ef0da2747ce..3ed4ec02aab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf1Entity.cs index 6428c3cfde8..a8058378a99 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.cs index 292a058cd5d..daba08e1c09 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ContainerStyle.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ContainerStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.DeterminesWhetherTheActionShouldBeEnabled.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.DeterminesWhetherTheActionShouldBeEnabled.cs index 78a8fa9d194..c6823241b59 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.DeterminesWhetherTheActionShouldBeEnabled.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.DeterminesWhetherTheActionShouldBeEnabled.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public DeterminesWhetherTheActionShouldBeEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.FallbackEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.FallbackEntity.cs index ed73ec691ff..c19cb83c2b2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.FallbackEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.FallbackEntity.cs @@ -767,6 +767,12 @@ private void CheckValidInstance() public FallbackEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.Mutable.cs index 94df8c9840e..8a142786f6c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.Mutable.cs @@ -894,6 +894,36 @@ public bool RemoveTooltip() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsEnabledUtf8, out IJsonDocument? _, out int _)) + { + SetIsEnabled(Corvus.Ui5ManifestBenchmark.Current.ExtendableAction.DeterminesWhetherTheActionShouldBeEnabled.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.cs index bddebe6bc30..ec9842c46bb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableAction.cs @@ -544,6 +544,12 @@ private void CheckValidInstance() public ExtendableAction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.FallbackEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.FallbackEntity.cs index f77c2b296f9..bcb60b870d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.FallbackEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.FallbackEntity.cs @@ -1298,6 +1298,12 @@ private void CheckValidInstance() public FallbackEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.Mutable.cs index 3b25be82df9..7d4b872dd2c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.Mutable.cs @@ -839,6 +839,31 @@ public bool RemoveSpacing() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.cs index 6ce590bef22..dd5eb717abb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableElement.cs @@ -507,6 +507,12 @@ private void CheckValidInstance() public ExtendableElement Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.FallbackEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.FallbackEntity.cs index 4d931897c3d..d2e4a945ec6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.FallbackEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.FallbackEntity.cs @@ -1298,6 +1298,12 @@ private void CheckValidInstance() public FallbackEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs index 6d45e0438a3..6d8b69e5e51 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IfFalseThisItemWillBeRemovedFromTheVisualTree Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.Mutable.cs index d213883e6f1..764e6465312 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.Mutable.cs @@ -933,6 +933,36 @@ public bool RemoveSpacing() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsVisibleUtf8, out IJsonDocument? _, out int _)) + { + SetIsVisible(Corvus.Ui5ManifestBenchmark.Current.ExtendableInput.IfFalseThisItemWillBeRemovedFromTheVisualTree.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.RequiresEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.RequiresEntity.cs index ef710781a57..f60faf94635 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.RequiresEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.RequiresEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public RequiresEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.cs index 8970bdfd896..ca57f7eeb52 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableInput.cs @@ -557,6 +557,12 @@ private void CheckValidInstance() public ExtendableInput Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.Mutable.cs index f38ee988213..e42986c5b85 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.Mutable.cs @@ -311,6 +311,31 @@ public bool RemoveRequires() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.RequiresEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.RequiresEntity.cs index ce1cc87d5dd..ab0d6f8cd8d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.RequiresEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.RequiresEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public RequiresEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.cs index 807316c2719..e83ed84100b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableItem.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public ExtendableItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs index d5cd5565459..f52d18d7f2d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IfFalseThisItemWillBeRemovedFromTheVisualTree Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.Mutable.cs index 39c4c9a530c..fbf997cec0f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.Mutable.cs @@ -456,6 +456,36 @@ public bool RemoveRequires() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsVisibleUtf8, out IJsonDocument? _, out int _)) + { + SetIsVisible(Corvus.Ui5ManifestBenchmark.Current.ExtendableToggleableItem.IfFalseThisItemWillBeRemovedFromTheVisualTree.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.cs index ec38f73c37a..4567a93afc0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ExtendableToggleableItem.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public ExtendableToggleableItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.MustBeFact.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.MustBeFact.cs index db81c0cc285..708893ec88e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.MustBeFact.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.MustBeFact.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeFact Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.Mutable.cs index 866866ce553..0d40a475e7d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.Mutable.cs @@ -312,6 +312,31 @@ public void SetValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.cs index 68a2283b2f6..d97751c0dab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Fact.cs @@ -337,6 +337,12 @@ private void CheckValidInstance() public Fact Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.FactArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.FactArray.cs index 38f4964b701..af60e7d9b97 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.FactArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.FactArray.cs @@ -26,11 +26,13 @@ public readonly partial struct FactSet public readonly partial struct FactArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public FactArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.MustBeFactSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.MustBeFactSet.cs index c7e72ecfd47..63165d5a439 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.MustBeFactSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.MustBeFactSet.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeFactSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.Mutable.cs index 862142ebaf8..7521d5b2db1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.Mutable.cs @@ -1024,6 +1024,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.cs index eb09204543a..7406bd7155f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FactSet.cs @@ -479,6 +479,12 @@ private void CheckValidInstance() public FactSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf0Entity.cs index 2b7073a480a..5290502c68d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf1Entity.cs index ac119cae699..a6ff6a7fd64 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.cs index 35df7f85dee..26241a85649 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FallbackOption.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public FallbackOption Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf0Entity.cs index baca7cc09d3..2c16343ad60 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf1Entity.cs index 23b5fbe143e..199188259b6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.cs index dddd9c5755c..edb1a4d14e9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontSize.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public FontSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf0Entity.cs index 8732ced0b6e..f3abbf481fd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf1Entity.cs index 8b4408fd29a..15df979ee63 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.cs index 05c9fc83198..bf56d2f4a87 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontType.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public FontType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf0Entity.cs index 1d30224f346..3b532642034 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf1Entity.cs index 23d810d8b15..6e3b87bd841 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.cs index 9f3dd778113..8c7e7982881 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/FontWeight.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public FontWeight Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf0Entity.cs index aa09f1288f9..75e0beda458 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf1Entity.cs index 691926db503..a5a903ec872 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.cs index 4a3fae212b8..1ab2b36335c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/HorizontalAlignment.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public HorizontalAlignment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.FallbackEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.FallbackEntity.cs index 91c96472493..150483d8366 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.FallbackEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.FallbackEntity.cs @@ -1298,6 +1298,12 @@ private void CheckValidInstance() public FallbackEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HeightEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HeightEntity.cs index d09dc8dae58..3d452228a91 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HeightEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HeightEntity.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public HeightEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HorizontalAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HorizontalAlignmentEntity.cs index 4f90a21ac9e..7e67a73842b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HorizontalAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.HorizontalAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HorizontalAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs index 2ad5a05f150..2ae6b8944e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.IfFalseThisItemWillBeRemovedFromTheVisualTree.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IfFalseThisItemWillBeRemovedFromTheVisualTree Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.MustBeImage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.MustBeImage.cs index 2ee723c0173..5496b3d3960 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.MustBeImage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.MustBeImage.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeImage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.Mutable.cs index c832d532121..c406844af81 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.Mutable.cs @@ -1298,6 +1298,41 @@ public bool RemoveWidth() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeightUtf8, out IJsonDocument? _, out int _)) + { + SetHeight(Corvus.Ui5ManifestBenchmark.Current.Image.HeightEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsVisibleUtf8, out IJsonDocument? _, out int _)) + { + SetIsVisible(Corvus.Ui5ManifestBenchmark.Current.Image.IfFalseThisItemWillBeRemovedFromTheVisualTree.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.RequiresEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.RequiresEntity.cs index e6d8676e372..85e5bf62a77 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.RequiresEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.RequiresEntity.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public RequiresEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.cs index 20f525902ca..783a1ef39c1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Image.cs @@ -616,6 +616,12 @@ private void CheckValidInstance() public Image Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf0Entity.cs index 8b1aeaeffa0..0c5b976c1ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf1Entity.cs index afc42d99dff..0fa0d4ae3ce 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.cs index af0c3ce958a..777793bb53d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageFillMode.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ImageFillMode Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.ImageArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.ImageArray.cs index ee4b840be07..08137af84db 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.ImageArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.ImageArray.cs @@ -26,11 +26,13 @@ public readonly partial struct ImageSet public readonly partial struct ImageArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImageArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.MustBeImageSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.MustBeImageSet.cs index a365a5a74d1..2a7a13d0e00 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.MustBeImageSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.MustBeImageSet.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeImageSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.Mutable.cs index 5d377807417..6ee56e7429b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.Mutable.cs @@ -1093,6 +1093,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.cs index a765bb4b15e..36b9ec5ec0c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSet.cs @@ -503,6 +503,12 @@ private void CheckValidInstance() public ImageSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf0Entity.cs index c8da3dfcdab..3eba2d5491e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf1Entity.cs index 804be92ca51..5d3155ae70a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.cs index f4802d06c06..cf1ac0f44c0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageSize.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ImageSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf0Entity.cs index e9f78d4edea..4bbc3ffe946 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf1Entity.cs index d74acca0890..58330a450ab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.cs index ba3480f0809..f13edf677f5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImageStyle.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ImageStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.Mutable.cs index efaba90d9ea..cefdda30420 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.Mutable.cs @@ -1249,6 +1249,31 @@ public void SetUrl(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonUriReferenc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.cs index 2f4b802f301..5f9940325c4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType.cs @@ -585,6 +585,12 @@ private void CheckValidInstance() public ImplementationsOfActionRequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.Mutable.cs index 996663ce7ac..d10b5f8f129 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.Mutable.cs @@ -1299,6 +1299,37 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ActionShowCard _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CardUtf8, out Corvus.Ui5ManifestBenchmark.Current.AdaptiveCard.Mutable __corvusCard)) + { + __corvusCard.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.cs index 8bc4a671b67..0019365eb75 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType1.cs @@ -585,6 +585,12 @@ private void CheckValidInstance() public ImplementationsOfActionRequiredType1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.Mutable.cs index 73778aefd5b..cd8b592702e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.Mutable.cs @@ -1362,6 +1362,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ActionSubmit.M _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.cs index 3c1e1023153..9b4f685c132 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType2.cs @@ -603,6 +603,12 @@ private void CheckValidInstance() public ImplementationsOfActionRequiredType2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.Mutable.cs index 9fb654d1fe1..3870f69e86f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.Mutable.cs @@ -1283,6 +1283,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ActionToggleVi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.cs index 88f5ec2cd0b..132d45d12e3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.ImplementationsOfActionRequiredType3.cs @@ -585,6 +585,12 @@ private void CheckValidInstance() public ImplementationsOfActionRequiredType3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.Mutable.cs index f3bb6f26f44..f7479f4df3f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.Mutable.cs @@ -1428,6 +1428,31 @@ public bool RemoveVerb() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.cs index 98abc1bde93..8cde464ddc2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.RequiredType.cs @@ -624,6 +624,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.cs index 57b21e59481..1e518a14aa0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfAction.cs @@ -597,6 +597,12 @@ private void CheckValidInstance() public ImplementationsOfAction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.Mutable.cs index 6a46aab194b..ae97631daa0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.Mutable.cs @@ -1486,6 +1486,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ColumnSet.Must _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.cs index bdac07d2dd5..fdc793103a6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType.cs @@ -673,6 +673,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.Mutable.cs index 6915bb9be43..68b63458143 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.Mutable.cs @@ -1526,6 +1526,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.cs index 4bacd5f1b08..d418047480c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType1.cs @@ -648,6 +648,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.Mutable.cs index 8ecd4f51ced..f014dda0ceb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.Mutable.cs @@ -1176,6 +1176,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ImageSet.MustB _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.cs index 88164c2aa26..07310d70a50 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType10.cs @@ -595,6 +595,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType10 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.Mutable.cs index f92d331a34b..2ca0935ed43 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.Mutable.cs @@ -1694,6 +1694,36 @@ public bool RemoveWrap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsMultiSelectUtf8, out IJsonDocument? _, out int _)) + { + SetIsMultiSelect(Corvus.Ui5ManifestBenchmark.Current.InputChoiceSet.AllowMultipleChoicesToBeSelected.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.cs index d2408ca8705..7f391eece25 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType11.cs @@ -690,6 +690,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType11 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.Mutable.cs index f4e558eaec0..5531cead411 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.Mutable.cs @@ -1526,6 +1526,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.cs index b1e0f08a76d..72d8a7891f6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType12.cs @@ -648,6 +648,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType12 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.Mutable.cs index 7961cbadac6..4bc2e2336a3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.Mutable.cs @@ -1526,6 +1526,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.cs index 18ae638d3ca..b148b9a9d9f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType13.cs @@ -648,6 +648,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType13 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.Mutable.cs index 970ae5fcc6a..63c2ba0847d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.Mutable.cs @@ -1763,6 +1763,36 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsMultilineUtf8, out IJsonDocument? _, out int _)) + { + SetIsMultiline(Corvus.Ui5ManifestBenchmark.Current.InputText.IfTrueAllowMultipleLinesOfInput.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.cs index 2e4e977903e..b1c1a02e0aa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType14.cs @@ -714,6 +714,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType14 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.Mutable.cs index 788f6c6e405..79f0cc2c944 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.Mutable.cs @@ -1581,6 +1581,46 @@ public bool RemoveWrap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueUtf8, out IJsonDocument? _, out int _)) + { + SetValue(Corvus.Ui5ManifestBenchmark.Current.InputToggle.ValueEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueOffUtf8, out IJsonDocument? _, out int _)) + { + SetValueOff(Corvus.Ui5ManifestBenchmark.Current.InputToggle.TheValueWhenToggleIsOff.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueOnUtf8, out IJsonDocument? _, out int _)) + { + SetValueOn(Corvus.Ui5ManifestBenchmark.Current.InputToggle.TheValueWhenToggleIsOn.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.cs index 481adade053..e3c8c6b11c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType2.cs @@ -672,6 +672,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.Mutable.cs index 8d14494c6ad..7fd1b6418f7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.Mutable.cs @@ -1239,6 +1239,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.Media.MustBeMe _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.cs index 12056ab465e..1add1acbc64 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType3.cs @@ -613,6 +613,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType3 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.Mutable.cs index b847b91d53e..76a3d06d7b5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.Mutable.cs @@ -1173,6 +1173,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.RichTextBlock. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.cs index 75065a877de..9f6429fe336 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType4.cs @@ -592,6 +592,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType4 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.Mutable.cs index 8d748b3b5c9..825f69542f8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.Mutable.cs @@ -1552,6 +1552,46 @@ public bool RemoveVerticalCellContentAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FirstRowAsHeaderUtf8, out IJsonDocument? _, out int _)) + { + SetFirstRowAsHeader(Corvus.Ui5ManifestBenchmark.Current.Table.FirstRowAsHeaderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GridStyleUtf8, out IJsonDocument? _, out int _)) + { + SetGridStyle(Corvus.Ui5ManifestBenchmark.Current.Table.GridStyleEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowGridLinesUtf8, out IJsonDocument? _, out int _)) + { + SetShowGridLines(Corvus.Ui5ManifestBenchmark.Current.Table.SpecifiesWhetherGridLinesShouldBeDisplayed.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.cs index 1116412145e..0131d19dcf1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType5.cs @@ -694,6 +694,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType5 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.Mutable.cs index ce5bc68e610..a2f9c8b20bd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.Mutable.cs @@ -1667,6 +1667,46 @@ public bool RemoveWrap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsSubtleUtf8, out IJsonDocument? _, out int _)) + { + SetIsSubtle(Corvus.Ui5ManifestBenchmark.Current.TextBlock.IsSubtleEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.Ui5ManifestBenchmark.Current.TextBlock.TheStyleOfThisTextBlockForAccessibilityPurposes.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WrapUtf8, out IJsonDocument? _, out int _)) + { + SetWrap(Corvus.Ui5ManifestBenchmark.Current.TextBlock.IfTrueAllowTextToWrapOtherwiseTextIsClipped.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.cs index dd3b3d3a67a..d6f13113c20 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType6.cs @@ -760,6 +760,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType6 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.Mutable.cs index 8d28ca905f7..30f1310a7aa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.Mutable.cs @@ -1641,6 +1641,31 @@ public bool RemoveVerticalContentAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.cs index b0d32799851..bc2e5fa3726 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType7.cs @@ -718,6 +718,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType7 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.Mutable.cs index d31c7834bbb..c9dd55a3e7d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.Mutable.cs @@ -1107,6 +1107,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.FactSet.MustBe _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.cs index 008405650ed..3bf02ae7973 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType8.cs @@ -571,6 +571,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType8 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.Mutable.cs index 6b9b26cd594..ef6d2b94364 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.Mutable.cs @@ -1381,6 +1381,41 @@ public bool RemoveWidth() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HeightUtf8, out IJsonDocument? _, out int _)) + { + SetHeight(Corvus.Ui5ManifestBenchmark.Current.Image.HeightEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsVisibleUtf8, out IJsonDocument? _, out int _)) + { + SetIsVisible(Corvus.Ui5ManifestBenchmark.Current.Image.IfFalseThisItemWillBeRemovedFromTheVisualTree.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.cs index 80d6ae6650e..a898d41961c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.ImplementationsOfElementRequiredType9.cs @@ -708,6 +708,12 @@ private void CheckValidInstance() public ImplementationsOfElementRequiredType9 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.Mutable.cs index c927c90f5d9..8ea4b1f6a79 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.Mutable.cs @@ -1107,6 +1107,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ActionSet.Must _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.cs index 65cf15ead01..09a5d3d6434 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.RequiredType.cs @@ -571,6 +571,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.cs index cf9b6178d87..96b9970fc43 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfElement.cs @@ -1128,6 +1128,12 @@ private void CheckValidInstance() public ImplementationsOfElement Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.Mutable.cs index be73cc22ab5..99b21d8a330 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.Mutable.cs @@ -1249,6 +1249,31 @@ public void SetUrl(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonUriReferenc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.cs index d370c294302..13d1338d9b2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType.cs @@ -585,6 +585,12 @@ private void CheckValidInstance() public ImplementationsOfISelectActionRequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.Mutable.cs index e43405d2b0d..ac78ea32438 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.Mutable.cs @@ -1362,6 +1362,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ActionSubmit.M _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.cs index e2c0cb1bafa..96e5d353aed 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType1.cs @@ -603,6 +603,12 @@ private void CheckValidInstance() public ImplementationsOfISelectActionRequiredType1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.Mutable.cs index 3428fb9cb68..6b6249dfcba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.Mutable.cs @@ -1283,6 +1283,31 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.ActionToggleVi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.cs index 24cea888ae7..5a2dd3aeb24 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.ImplementationsOfISelectActionRequiredType2.cs @@ -585,6 +585,12 @@ private void CheckValidInstance() public ImplementationsOfISelectActionRequiredType2 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.Mutable.cs index 0aba5aa71af..53da348c004 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.Mutable.cs @@ -1428,6 +1428,31 @@ public bool RemoveVerb() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.cs index 950ebe23d36..45db8dcdf94 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.RequiredType.cs @@ -624,6 +624,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.cs index a8fc7934f66..9a612100439 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfISelectAction.cs @@ -552,6 +552,12 @@ private void CheckValidInstance() public ImplementationsOfISelectAction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.Mutable.cs index 29cf8580de8..7c5db14b7d9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.Mutable.cs @@ -388,6 +388,31 @@ public void SetType(in Corvus.Text.Json.JsonElement.Source v _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.cs index 637d642597d..ab9abd77d8d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.RequiredType.cs @@ -450,6 +450,12 @@ private void CheckValidInstance() public RequiredType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.cs index a744381a269..114062d4cd7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/ImplementationsOfInline.cs @@ -453,6 +453,12 @@ private void CheckValidInstance() public ImplementationsOfInline Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.MustBeInputChoice.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.MustBeInputChoice.cs index 9e15e206664..07ad27fe560 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.MustBeInputChoice.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.MustBeInputChoice.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeInputChoice Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.Mutable.cs index a864d4db626..74ebe65bab1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.Mutable.cs @@ -312,6 +312,31 @@ public void SetValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.cs index 3bdb79b17a6..e739a5ef9c7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoice.cs @@ -337,6 +337,12 @@ private void CheckValidInstance() public InputChoice Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.AllowMultipleChoicesToBeSelected.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.AllowMultipleChoicesToBeSelected.cs index 6d65b22e67a..5ee496f74f3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.AllowMultipleChoicesToBeSelected.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.AllowMultipleChoicesToBeSelected.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public AllowMultipleChoicesToBeSelected Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.InputChoiceArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.InputChoiceArray.cs index 2c3e05ebf96..769fbdda3d1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.InputChoiceArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.InputChoiceArray.cs @@ -26,11 +26,13 @@ public readonly partial struct InputChoiceSet public readonly partial struct InputChoiceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public InputChoiceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.MustBeInputChoiceSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.MustBeInputChoiceSet.cs index 47886e52397..0c08479e734 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.MustBeInputChoiceSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.MustBeInputChoiceSet.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeInputChoiceSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.Mutable.cs index 8da5a33bba6..caf2079ae31 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.Mutable.cs @@ -1611,6 +1611,36 @@ public bool RemoveWrap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsMultiSelectUtf8, out IJsonDocument? _, out int _)) + { + SetIsMultiSelect(Corvus.Ui5ManifestBenchmark.Current.InputChoiceSet.AllowMultipleChoicesToBeSelected.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.cs index 8bfaf0e5739..1a5edfa6989 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputChoiceSet.cs @@ -598,6 +598,12 @@ private void CheckValidInstance() public InputChoiceSet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.MustBeInputDate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.MustBeInputDate.cs index 8076f65ebc8..9bc7b5fdded 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.MustBeInputDate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.MustBeInputDate.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeInputDate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.Mutable.cs index ed8a42380b6..1507c4fa72f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.Mutable.cs @@ -1443,6 +1443,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.cs index e9cf22fd2ca..64ae4b3444f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputDate.cs @@ -556,6 +556,12 @@ private void CheckValidInstance() public InputDate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.MustBeInputNumber.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.MustBeInputNumber.cs index 6b24f48a310..f057a477791 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.MustBeInputNumber.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.MustBeInputNumber.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeInputNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.Mutable.cs index 10033d44e3b..7a2c8f43c25 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.Mutable.cs @@ -1443,6 +1443,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.cs index a9f120bfe1f..7e6c469f476 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputNumber.cs @@ -556,6 +556,12 @@ private void CheckValidInstance() public InputNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.IfTrueAllowMultipleLinesOfInput.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.IfTrueAllowMultipleLinesOfInput.cs index 325283966a8..a51a0843904 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.IfTrueAllowMultipleLinesOfInput.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.IfTrueAllowMultipleLinesOfInput.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IfTrueAllowMultipleLinesOfInput Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.MustBeInputText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.MustBeInputText.cs index bcd745a5401..e5493182ae3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.MustBeInputText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.MustBeInputText.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeInputText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.Mutable.cs index 272c44ffa9f..1e47cc250d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.Mutable.cs @@ -1680,6 +1680,36 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsMultilineUtf8, out IJsonDocument? _, out int _)) + { + SetIsMultiline(Corvus.Ui5ManifestBenchmark.Current.InputText.IfTrueAllowMultipleLinesOfInput.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.cs index 28d9c291655..11463f5b980 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputText.cs @@ -622,6 +622,12 @@ private void CheckValidInstance() public InputText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.MustBeInputTime.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.MustBeInputTime.cs index 61bdf0a135e..fc81c14eecf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.MustBeInputTime.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.MustBeInputTime.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeInputTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.Mutable.cs index 66a3f8ca52f..e3e53727d52 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.Mutable.cs @@ -1443,6 +1443,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.cs index b9bb5879981..11fb0871dec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputTime.cs @@ -556,6 +556,12 @@ private void CheckValidInstance() public InputTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.MustBeInputToggle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.MustBeInputToggle.cs index 1662fe36ac7..7de7a316124 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.MustBeInputToggle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.MustBeInputToggle.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeInputToggle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.Mutable.cs index 79bdc4c95f4..9e193b47ca6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.Mutable.cs @@ -1498,6 +1498,46 @@ public bool RemoveWrap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueUtf8, out IJsonDocument? _, out int _)) + { + SetValue(Corvus.Ui5ManifestBenchmark.Current.InputToggle.ValueEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueOffUtf8, out IJsonDocument? _, out int _)) + { + SetValueOff(Corvus.Ui5ManifestBenchmark.Current.InputToggle.TheValueWhenToggleIsOff.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueOnUtf8, out IJsonDocument? _, out int _)) + { + SetValueOn(Corvus.Ui5ManifestBenchmark.Current.InputToggle.TheValueWhenToggleIsOn.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOff.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOff.cs index d1708d48e8d..bbd6fa0b47a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOff.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOff.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public TheValueWhenToggleIsOff Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOn.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOn.cs index b1d3f9e7f61..98d32534d4a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOn.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.TheValueWhenToggleIsOn.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public TheValueWhenToggleIsOn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.ValueEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.ValueEntity.cs index 2b8708f373e..11d1a641fac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.ValueEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.cs index db36d98f1ac..6e736764ddf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/InputToggle.cs @@ -580,6 +580,12 @@ private void CheckValidInstance() public InputToggle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonArray.cs index ac0b3d3db70..1c155e4d6a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonArray.cs @@ -23,11 +23,13 @@ namespace Corvus.Ui5ManifestBenchmark.Current; public readonly partial struct JsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public JsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonBoolean.cs index cfb8bda8649..987de7dba61 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonInteger.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonInteger.cs index 0b940c276d4..44a3590a911 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonInteger.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonInteger.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNull.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNull.cs index 3ba9805ffea..a891d5801bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNull.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNull.cs @@ -256,6 +256,12 @@ private void CheckValidInstance() public JsonNull Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNumber.cs index 1c530d16e02..f65752d8f82 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonNumber.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonObject.cs index 9adc0bfcfc6..0dfb1cc63b3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonRegex.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonRegex.cs index 559a113f76c..e51d13a1bb0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonRegex.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonRegex.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonRegex Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonString.cs index 9b6b6f67b8c..d2c737e0c31 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUri.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUri.cs index 0564067fa4d..0ff67d2e9c0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUri.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUri.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public JsonUri Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriReference.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriReference.cs index b663d61523e..ba0bbd9a324 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriReference.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriReference.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public JsonUriReference Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriTemplate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriTemplate.cs index ab1782fb029..8a4cbcb9e39 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriTemplate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/JsonUriTemplate.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonUriTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MediaSourceArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MediaSourceArray.cs index 2d623448647..2e4c346cb71 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MediaSourceArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MediaSourceArray.cs @@ -26,11 +26,13 @@ public readonly partial struct Media public readonly partial struct MediaSourceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public MediaSourceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MustBeMedia.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MustBeMedia.cs index f866ba34475..fa757cb571f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MustBeMedia.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.MustBeMedia.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeMedia Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.Mutable.cs index 13b590f652c..e80881b1629 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.Mutable.cs @@ -1156,6 +1156,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.cs index 5f693039e71..180b4406d58 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Media.cs @@ -521,6 +521,12 @@ private void CheckValidInstance() public Media Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.MustBeMediaSource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.MustBeMediaSource.cs index a69f24e6ff9..19f00261ea8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.MustBeMediaSource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.MustBeMediaSource.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeMediaSource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.Mutable.cs index 0ef90bc98c6..e0b09d66a7c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.Mutable.cs @@ -312,6 +312,31 @@ public void SetUrl(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonUriReferenc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.cs index 0508c5e2ed6..87274ffe9d6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/MediaSource.cs @@ -337,6 +337,12 @@ private void CheckValidInstance() public MediaSource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.JsonStringArray.cs index c9c888ee67b..f5bf2e373f3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.JsonStringArray.cs @@ -26,11 +26,13 @@ public readonly partial struct Refresh public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.MustBeRefresh.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.MustBeRefresh.cs index 8b8154c3a09..1206f79c367 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.MustBeRefresh.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.MustBeRefresh.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeRefresh Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.Mutable.cs index e6b18348950..fc896001647 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.Mutable.cs @@ -409,6 +409,37 @@ public bool RemoveUserIds() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ActionUtf8, out Corvus.Ui5ManifestBenchmark.Current.ActionExecute.Mutable __corvusAction)) + { + __corvusAction.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.cs index bc17224a56d..b1665a09e9a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Refresh.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public Refresh Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.HorizontalAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.HorizontalAlignmentEntity.cs index 127ff5bed79..2d8d717d5da 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.HorizontalAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.HorizontalAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HorizontalAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.ImplementationsOfInlineArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.ImplementationsOfInlineArray.cs index 2166c342e14..e6e417eafa6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.ImplementationsOfInlineArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.ImplementationsOfInlineArray.cs @@ -26,11 +26,13 @@ public readonly partial struct RichTextBlock public readonly partial struct ImplementationsOfInlineArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImplementationsOfInlineArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.MustBeRichTextBlock.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.MustBeRichTextBlock.cs index 6abf8635849..6f4c437b29c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.MustBeRichTextBlock.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.MustBeRichTextBlock.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeRichTextBlock Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.Mutable.cs index 20200a33b5f..841d2d27a63 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.Mutable.cs @@ -1090,6 +1090,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.cs index 5fe1d3eb84a..3385a6be23d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/RichTextBlock.cs @@ -500,6 +500,12 @@ private void CheckValidInstance() public RichTextBlock Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf0Entity.cs index 532eca06566..2106377988b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf1Entity.cs index a3544b7bf47..895e43cc423 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.cs index 9496a771ac9..779a7443624 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Spacing.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public Spacing Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.FirstRowAsHeaderEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.FirstRowAsHeaderEntity.cs index caedead0bd5..03af4784e67 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.FirstRowAsHeaderEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.FirstRowAsHeaderEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public FirstRowAsHeaderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.GridStyleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.GridStyleEntity.cs index f0b366bdeac..fc1d789e5a4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.GridStyleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.GridStyleEntity.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public GridStyleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.HorizontalCellContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.HorizontalCellContentAlignmentEntity.cs index a17cdca58a0..7b21fec78e3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.HorizontalCellContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.HorizontalCellContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HorizontalCellContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.MustBeTable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.MustBeTable.cs index 52525f777c4..2f692e6ae6d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.MustBeTable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.MustBeTable.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeTable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.Mutable.cs index 323e234675e..5ca4f25adc6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.Mutable.cs @@ -1469,6 +1469,46 @@ public bool RemoveVerticalCellContentAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FirstRowAsHeaderUtf8, out IJsonDocument? _, out int _)) + { + SetFirstRowAsHeader(Corvus.Ui5ManifestBenchmark.Current.Table.FirstRowAsHeaderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GridStyleUtf8, out IJsonDocument? _, out int _)) + { + SetGridStyle(Corvus.Ui5ManifestBenchmark.Current.Table.GridStyleEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowGridLinesUtf8, out IJsonDocument? _, out int _)) + { + SetShowGridLines(Corvus.Ui5ManifestBenchmark.Current.Table.SpecifiesWhetherGridLinesShouldBeDisplayed.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.SpecifiesWhetherGridLinesShouldBeDisplayed.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.SpecifiesWhetherGridLinesShouldBeDisplayed.cs index def90b612e0..20cc67eb976 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.SpecifiesWhetherGridLinesShouldBeDisplayed.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.SpecifiesWhetherGridLinesShouldBeDisplayed.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public SpecifiesWhetherGridLinesShouldBeDisplayed Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableColumnDefinitionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableColumnDefinitionArray.cs index bbe5aba51de..3750d82f0e6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableColumnDefinitionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableColumnDefinitionArray.cs @@ -26,11 +26,13 @@ public readonly partial struct Table public readonly partial struct TableColumnDefinitionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TableColumnDefinitionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableRowArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableRowArray.cs index ddd18397981..3fd242350c4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableRowArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.TableRowArray.cs @@ -26,11 +26,13 @@ public readonly partial struct Table public readonly partial struct TableRowArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TableRowArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.VerticalCellContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.VerticalCellContentAlignmentEntity.cs index c650ad41ffe..16dcd016762 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.VerticalCellContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.VerticalCellContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public VerticalCellContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.cs index a2c8d5d6088..f9d21cd7de9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Table.cs @@ -602,6 +602,12 @@ private void CheckValidInstance() public Table Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.BackgroundImageEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.BackgroundImageEntity.cs index 1bb5c3be680..3f9a0275b57 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.BackgroundImageEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.BackgroundImageEntity.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public BackgroundImageEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.ImplementationsOfElementArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.ImplementationsOfElementArray.cs index 0aae143a45f..2b02f250c8f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.ImplementationsOfElementArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.ImplementationsOfElementArray.cs @@ -26,11 +26,13 @@ public readonly partial struct TableCell public readonly partial struct ImplementationsOfElementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ImplementationsOfElementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.MustBeTableCell.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.MustBeTableCell.cs index 6fd4449ab9b..9729c9538ee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.MustBeTableCell.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.MustBeTableCell.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeTableCell Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.Mutable.cs index a377aaff724..1851de2a068 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.Mutable.cs @@ -825,6 +825,31 @@ public bool RemoveVerticalContentAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.RtlEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.RtlEntity.cs index c8a8d20e8e9..6392929db73 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.RtlEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.RtlEntity.cs @@ -306,6 +306,12 @@ private void CheckValidInstance() public RtlEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.StyleHintForTableCell.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.StyleHintForTableCell.cs index c54b7a98275..11c07bfed58 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.StyleHintForTableCell.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.StyleHintForTableCell.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public StyleHintForTableCell Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.VerticalContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.VerticalContentAlignmentEntity.cs index 1cb03e1fbf0..b2dcf2bd8ac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.VerticalContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.VerticalContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public VerticalContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.cs index 1b2b0d3d559..ed4259afc7c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableCell.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public TableCell Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.HorizontalCellContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.HorizontalCellContentAlignmentEntity.cs index 9b95e767f3c..599f26cbb55 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.HorizontalCellContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.HorizontalCellContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HorizontalCellContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.MustBeTableColumnDefinition.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.MustBeTableColumnDefinition.cs index c45cfd42011..01f42f503dc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.MustBeTableColumnDefinition.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.MustBeTableColumnDefinition.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeTableColumnDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.Mutable.cs index bc7a7cedf2e..af700baa78d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.Mutable.cs @@ -400,6 +400,36 @@ public bool RemoveWidth() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WidthUtf8, out IJsonDocument? _, out int _)) + { + SetWidth(Corvus.Ui5ManifestBenchmark.Current.TableColumnDefinition.WidthEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.VerticalCellContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.VerticalCellContentAlignmentEntity.cs index 17361accc05..d133d987843 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.VerticalCellContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.VerticalCellContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public VerticalCellContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.WidthEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.WidthEntity.cs index 020213101ee..a5c71d2f0a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.WidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.WidthEntity.cs @@ -464,6 +464,12 @@ private void CheckValidInstance() public WidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.cs index 1ca2b1ed862..6e01dfe6993 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableColumnDefinition.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public TableColumnDefinition Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.DefinesTheStyleOfTheEntireRow.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.DefinesTheStyleOfTheEntireRow.cs index aca884a9faf..17721f2bb1d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.DefinesTheStyleOfTheEntireRow.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.DefinesTheStyleOfTheEntireRow.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public DefinesTheStyleOfTheEntireRow Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.HorizontalCellContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.HorizontalCellContentAlignmentEntity.cs index b2e85f677b4..d4a67c4f101 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.HorizontalCellContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.HorizontalCellContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HorizontalCellContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.MustBeTableRow.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.MustBeTableRow.cs index 34b4ef89f40..10f92b0e365 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.MustBeTableRow.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.MustBeTableRow.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeTableRow Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.Mutable.cs index a17dfc5bbbd..3eea488068d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.Mutable.cs @@ -502,6 +502,31 @@ public bool RemoveVerticalCellContentAlignment() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.TableCellArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.TableCellArray.cs index e5ec301baeb..9f5233f73c2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.TableCellArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.TableCellArray.cs @@ -26,11 +26,13 @@ public readonly partial struct TableRow public readonly partial struct TableCellArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public TableCellArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.VerticalCellContentAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.VerticalCellContentAlignmentEntity.cs index 3d52bf7b121..d38a057c049 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.VerticalCellContentAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.VerticalCellContentAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public VerticalCellContentAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.cs index 4dfb26dcb2f..f771dc83d92 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TableRow.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public TableRow Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.IsVisibleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.IsVisibleEntity.cs index fabad995169..b43d0c21289 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.IsVisibleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.IsVisibleEntity.cs @@ -308,6 +308,12 @@ private void CheckValidInstance() public IsVisibleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.MustBeTargetElement.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.MustBeTargetElement.cs index 51b5a83f335..7c476c22d52 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.MustBeTargetElement.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.MustBeTargetElement.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public MustBeTargetElement Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.Mutable.cs index 80efd38044c..c55c7bfcc99 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.Mutable.cs @@ -326,6 +326,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.cs index 829725b29eb..8a1aeacb8cf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.RequiredElementId.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public RequiredElementId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.cs index fb3c8055251..7222aefeab2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TargetElement.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public TargetElement Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsSizeOfText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsSizeOfText.cs index c6b8e75f2af..dba2e4144da 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsSizeOfText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsSizeOfText.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public ControlsSizeOfText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheColorOfTextBlockElements.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheColorOfTextBlockElements.cs index 086cb3778d7..ca6948c455a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheColorOfTextBlockElements.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheColorOfTextBlockElements.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public ControlsTheColorOfTextBlockElements Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheWeightOfTextBlockElements.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheWeightOfTextBlockElements.cs index 6edcab42a30..96aa98f5ac7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheWeightOfTextBlockElements.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.ControlsTheWeightOfTextBlockElements.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public ControlsTheWeightOfTextBlockElements Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.HorizontalAlignmentEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.HorizontalAlignmentEntity.cs index 4a8fbc77aaa..f85d6d0fd75 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.HorizontalAlignmentEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.HorizontalAlignmentEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HorizontalAlignmentEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IfTrueAllowTextToWrapOtherwiseTextIsClipped.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IfTrueAllowTextToWrapOtherwiseTextIsClipped.cs index 5f7dfb3fbed..77226c68c0d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IfTrueAllowTextToWrapOtherwiseTextIsClipped.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IfTrueAllowTextToWrapOtherwiseTextIsClipped.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IfTrueAllowTextToWrapOtherwiseTextIsClipped Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IsSubtleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IsSubtleEntity.cs index 662edc5f43f..f6119c397e2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IsSubtleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.IsSubtleEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IsSubtleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.MustBeTextBlock.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.MustBeTextBlock.cs index 2ff391593f2..a9b9069ce46 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.MustBeTextBlock.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.MustBeTextBlock.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeTextBlock Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.Mutable.cs index dbb421b2d35..baedbe6223d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.Mutable.cs @@ -1584,6 +1584,46 @@ public bool RemoveWrap() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsSubtleUtf8, out IJsonDocument? _, out int _)) + { + SetIsSubtle(Corvus.Ui5ManifestBenchmark.Current.TextBlock.IsSubtleEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StyleUtf8, out IJsonDocument? _, out int _)) + { + SetStyle(Corvus.Ui5ManifestBenchmark.Current.TextBlock.TheStyleOfThisTextBlockForAccessibilityPurposes.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WrapUtf8, out IJsonDocument? _, out int _)) + { + SetWrap(Corvus.Ui5ManifestBenchmark.Current.TextBlock.IfTrueAllowTextToWrapOtherwiseTextIsClipped.DefaultInstance); + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TheStyleOfThisTextBlockForAccessibilityPurposes.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TheStyleOfThisTextBlockForAccessibilityPurposes.cs index 02a1cd1aa2b..ab8ffb5c0fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TheStyleOfThisTextBlockForAccessibilityPurposes.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TheStyleOfThisTextBlockForAccessibilityPurposes.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public TheStyleOfThisTextBlockForAccessibilityPurposes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TypeOfFontToUseForRendering.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TypeOfFontToUseForRendering.cs index 2c4635fed71..c73496bbf5a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TypeOfFontToUseForRendering.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.TypeOfFontToUseForRendering.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public TypeOfFontToUseForRendering Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.cs index b9da9db68da..43bca11b5aa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlock.cs @@ -668,6 +668,12 @@ private void CheckValidInstance() public TextBlock Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf0Entity.cs index 3521a8d7b11..bfaf1e3fd87 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf1Entity.cs index 5fa9381f4cf..1ec87f1454b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.cs index 4e3cf2ffbfd..2b0adde2de5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextBlockStyle.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public TextBlockStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf0Entity.cs index 0440dcd2783..dbc53d584bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf1Entity.cs index 9d48cd9460b..a3141793e67 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.cs index 7f76b678d5d..9267d6c8c4c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextInputStyle.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public TextInputStyle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsSizeOfText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsSizeOfText.cs index 7673fe911f2..d9d6c95a54b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsSizeOfText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsSizeOfText.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public ControlsSizeOfText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheColorOfTheText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheColorOfTheText.cs index 30373019376..c30dd78a6ab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheColorOfTheText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheColorOfTheText.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public ControlsTheColorOfTheText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheWeightOfTheText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheWeightOfTheText.cs index 9f88e481748..da4dffdd383 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheWeightOfTheText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.ControlsTheWeightOfTheText.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public ControlsTheWeightOfTheText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.IsSubtleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.IsSubtleEntity.cs index 745c1577875..c5033d6af3e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.IsSubtleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.IsSubtleEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IsSubtleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.MustBeTextRun.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.MustBeTextRun.cs index 7af2cdfe00b..170405e8fb5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.MustBeTextRun.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.MustBeTextRun.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public MustBeTextRun Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.Mutable.cs index eb16725e0b8..52cd1eb545b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.Mutable.cs @@ -956,6 +956,36 @@ public bool RemoveWeight() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsSubtleUtf8, out IJsonDocument? _, out int _)) + { + SetIsSubtle(Corvus.Ui5ManifestBenchmark.Current.TextRun.RequiredText.IsSubtleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.TheTypeOfFontToUse.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.TheTypeOfFontToUse.cs index ece46e52c27..c2eff5abb9d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.TheTypeOfFontToUse.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.TheTypeOfFontToUse.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public TheTypeOfFontToUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.cs index 63c80465833..4acd525faf5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.RequiredText.cs @@ -521,6 +521,12 @@ private void CheckValidInstance() public RequiredText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.cs index 98a0338a413..2aee9942736 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TextRun.cs @@ -422,6 +422,12 @@ private void CheckValidInstance() public TextRun Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.MustBeTokenExchangeResource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.MustBeTokenExchangeResource.cs index 816db8d7fc8..558ac2dcfca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.MustBeTokenExchangeResource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.MustBeTokenExchangeResource.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public MustBeTokenExchangeResource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.Mutable.cs index a8f47926d51..19c82b84de0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.Mutable.cs @@ -367,6 +367,31 @@ public void SetUriValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.cs index 3e71d191fd6..b76a74eee34 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/TokenExchangeResource.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public TokenExchangeResource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.Mutable.cs index 00366e27975..3d8b591ca23 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.Mutable.cs @@ -632,6 +632,37 @@ public bool RemoveUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServiceValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Service.Mutable __corvusServiceValue)) + { + __corvusServiceValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.ParametersPassedToTheNavigationActionHandler.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.ParametersPassedToTheNavigationActionHandler.cs index 906b7757c74..597262c9660 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.ParametersPassedToTheNavigationActionHandler.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.ParametersPassedToTheNavigationActionHandler.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public ParametersPassedToTheNavigationActionHandler Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.RepresentsTheStateOfTheAction.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.RepresentsTheStateOfTheAction.cs index 52c5cb6039d..c05511f2694 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.RepresentsTheStateOfTheAction.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.RepresentsTheStateOfTheAction.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public RepresentsTheStateOfTheAction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.SpecifiesWhereToOpenTheUrlIfItIsProvided.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.SpecifiesWhereToOpenTheUrlIfItIsProvided.cs index b9b990a00e8..52c95a45ec2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.SpecifiesWhereToOpenTheUrlIfItIsProvided.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.SpecifiesWhereToOpenTheUrlIfItIsProvided.cs @@ -454,6 +454,12 @@ private void CheckValidInstance() public SpecifiesWhereToOpenTheUrlIfItIsProvided Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.OneOf0Entity.cs index fa3594b7f25..97492e56fd6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.OneOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.cs index 46db2b6c126..63158d364c1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.TheTypeOfTheAction.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheAction Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.cs index 417b13d0ab0..d25e4d5a21a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Action.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public Action Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.Mutable.cs index 544699a86fa..6008531f7ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.Mutable.cs @@ -351,6 +351,37 @@ public void SetTarget(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.S _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RefreshStrategyOnAppRestoreUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RefreshStrategiesPropDef.Mutable __corvusRefreshStrategyOnAppRestore)) + { + __corvusRefreshStrategyOnAppRestore.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.cs index 58c7e3415a1..00829f783f7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionPropDef.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public ActionPropDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.ActionArray.cs index 69c20dc0ea5..64c6d985a92 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ActionsStripItem public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.OneOf0Entity.cs index c7f2c3da563..5ecdf79471e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.cs index ed6a589fd8b..bca0e723271 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.AriaHasPopupEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public AriaHasPopupEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.OneOf0Entity.cs index 73a01e98294..54001f39be7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.cs index ff162a1dd30..c96ec0a7e60 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DefinesItemsPriority.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DefinesItemsPriority Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DeterminesWhetherTheItemIsVisible.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DeterminesWhetherTheItemIsVisible.cs index 42cd864b672..590df372353 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DeterminesWhetherTheItemIsVisible.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.DeterminesWhetherTheItemIsVisible.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DeterminesWhetherTheItemIsVisible Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.Mutable.cs index c5adf6f0c6c..d37f2c3ef2a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.Mutable.cs @@ -769,6 +769,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.OneOf0Entity.cs index 7f19c7096b4..dbbe402f23a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.cs index 37a35243b53..473f00ef327 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheButton.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheButton Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.OneOf0Entity.cs index d3e8e9cc692..ad50e8b72e6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.cs index 02e85d6f7b3..827aef7a6bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.TheTypeOfTheItem.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.cs index 2fdb20ca955..39020bcdb3a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ActionsStripItem.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public ActionsStripItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.Mutable.cs index fbf100c1a21..e1de835374b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.Mutable.cs @@ -453,6 +453,31 @@ public void SetUrl(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsHttpHeaders.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsHttpHeaders.cs index 6c43080f18e..a2472903c8d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsHttpHeaders.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsHttpHeaders.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public RepresentsHttpHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsTheRequestBody.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsTheRequestBody.cs index 0ae4f915e30..b8e049d1470 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsTheRequestBody.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.RepresentsTheRequestBody.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public RepresentsTheRequestBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.TheHttpMethod.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.TheHttpMethod.cs index 3c9156c8a99..28430541e77 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.TheHttpMethod.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.TheHttpMethod.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TheHttpMethod Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.cs index 51f6da44308..8d77390b174 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BatchRequest.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public BatchRequest Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BooleanOrString.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BooleanOrString.cs index cceefe11da2..bfb5f39248f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BooleanOrString.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.BooleanOrString.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public BooleanOrString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.DeprecatedSetToTrueToDisableCachingForThisCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.DeprecatedSetToTrueToDisableCachingForThisCard.cs index 4b1618fb557..44a381b9a09 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.DeprecatedSetToTrueToDisableCachingForThisCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.DeprecatedSetToTrueToDisableCachingForThisCard.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DeprecatedSetToTrueToDisableCachingForThisCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.Mutable.cs index bc7d93614d6..c13125b815e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.Mutable.cs @@ -403,6 +403,51 @@ public bool RemoveStaleWhileRevalidate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Cache.SetToFalseToDisableCachingForThisCard.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MaxAgeUtf8, out IJsonDocument? _, out int _)) + { + SetMaxAge(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Cache.TheMaximumAgeForWhichTheCacheIsConsideredFresh.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NoStoreUtf8, out IJsonDocument? _, out int _)) + { + SetNoStore(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Cache.DeprecatedSetToTrueToDisableCachingForThisCard.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StaleWhileRevalidateUtf8, out IJsonDocument? _, out int _)) + { + SetStaleWhileRevalidate(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Cache.ShouldWeShowStaleCacheWhileRevalidating.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.SetToFalseToDisableCachingForThisCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.SetToFalseToDisableCachingForThisCard.cs index 680355740b4..7da83b8a9ca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.SetToFalseToDisableCachingForThisCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.SetToFalseToDisableCachingForThisCard.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public SetToFalseToDisableCachingForThisCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.ShouldWeShowStaleCacheWhileRevalidating.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.ShouldWeShowStaleCacheWhileRevalidating.cs index 66251c57e06..d6fdb7f4d04 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.ShouldWeShowStaleCacheWhileRevalidating.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.ShouldWeShowStaleCacheWhileRevalidating.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShouldWeShowStaleCacheWhileRevalidating Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.TheMaximumAgeForWhichTheCacheIsConsideredFresh.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.TheMaximumAgeForWhichTheCacheIsConsideredFresh.cs index 33748c0776b..1e15021d188 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.TheMaximumAgeForWhichTheCacheIsConsideredFresh.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.TheMaximumAgeForWhichTheCacheIsConsideredFresh.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public TheMaximumAgeForWhichTheCacheIsConsideredFresh Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.cs index e6d9fcf7e32..1314c0b0143 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Cache.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public Cache Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.Mutable.cs index 6f2922056ca..d8654873b3e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.Mutable.cs @@ -530,6 +530,37 @@ public void SetTemplate(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5Manifes _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheCardComponentPathToUseForThisCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheCardComponentPathToUseForThisCard.cs index e1f7ce2afdf..72374df7831 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheCardComponentPathToUseForThisCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheCardComponentPathToUseForThisCard.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheCardComponentPathToUseForThisCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheModelForTheCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheModelForTheCard.cs index 2d11c1f7f31..c7b4b24fd5c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheModelForTheCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.RepresentsTheModelForTheCard.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheModelForTheCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.TabSettingArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.TabSettingArray.cs index d964cc621dd..7864b742f2b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.TabSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.TabSettingArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Card public readonly partial struct TabSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public TabSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.cs index 838c88087b5..55c5cfd6659 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Card.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public Card Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.Mutable.cs index abf4ecfdf2d..0689f9a7ba5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.Mutable.cs @@ -345,6 +345,43 @@ public bool RemoveTimeAxis() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PlotAreaUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.PlotAreaDef.Mutable __corvusPlotArea)) + { + __corvusPlotArea.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TimeAxisUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.TimeAxisDef.Mutable __corvusTimeAxis)) + { + __corvusTimeAxis.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.cs index bce5fcd7161..198065548af 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public ChartPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.JsonObjectArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.JsonObjectArray.cs index 044cb395c6c..d8833aa829e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.JsonObjectArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.JsonObjectArray.cs @@ -25,11 +25,13 @@ public readonly partial struct ColorPaletteEntity public readonly partial struct JsonObjectArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonObjectArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.cs index 180e69cf65c..e4561ac12ee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ColorPaletteEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public ColorPaletteEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.CustomParamsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.CustomParamsEntity.cs index 05c73279b8f..838ebe436ca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.CustomParamsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.CustomParamsEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public CustomParamsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableAddToInsightsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableAddToInsightsEntity.cs index a6cd5bc0bae..7af857a25a4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableAddToInsightsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableAddToInsightsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableAddToInsightsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableLocaleCurrencyFormattingEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableLocaleCurrencyFormattingEntity.cs index b8e4a7ea1c9..afa96d04c77 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableLocaleCurrencyFormattingEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.EnableLocaleCurrencyFormattingEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableLocaleCurrencyFormattingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForEnablingImagesInACondensedListCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForEnablingImagesInACondensedListCard.cs index 648ea6dc0ed..56a804f6d06 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForEnablingImagesInACondensedListCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForEnablingImagesInACondensedListCard.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public FlagForEnablingImagesInACondensedListCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForShowLineItemDetailInListAndTableCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForShowLineItemDetailInListAndTableCard.cs index 26ce6f6f3de..ec5ff317441 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForShowLineItemDetailInListAndTableCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.FlagForShowLineItemDetailInListAndTableCard.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public FlagForShowLineItemDetailInListAndTableCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.IgnoreSapTextEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.IgnoreSapTextEntity.cs index a1c4170304b..abc98cccd76 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.IgnoreSapTextEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.IgnoreSapTextEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IgnoreSapTextEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.JsonObjectArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.JsonObjectArray.cs index e7682ee4cef..0c90587384f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.JsonObjectArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.JsonObjectArray.cs @@ -28,11 +28,13 @@ public readonly partial struct CardSetting public readonly partial struct JsonObjectArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonObjectArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListFlavorEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListFlavorEntity.cs index 89069527c41..52957409cef 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListFlavorEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListFlavorEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ListFlavorEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListTypeEntity.cs index c55d57c3765..2837bfa0800 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ListTypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ListTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.Mutable.cs index f05904fc1a4..91c30567405 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.Mutable.cs @@ -2757,6 +2757,88 @@ public bool RemoveValueSelectionInfo() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableAddToInsightsUtf8, out IJsonDocument? _, out int _)) + { + SetEnableAddToInsights(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.EnableAddToInsightsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableLocaleCurrencyFormattingUtf8, out IJsonDocument? _, out int _)) + { + SetEnableLocaleCurrencyFormatting(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.EnableLocaleCurrencyFormattingEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IgnoreSapTextUtf8, out IJsonDocument? _, out int _)) + { + SetIgnoreSapText(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.IgnoreSapTextEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImageSupportedUtf8, out IJsonDocument? _, out int _)) + { + SetImageSupported(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.FlagForEnablingImagesInACondensedListCard.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowFilterInHeaderUtf8, out IJsonDocument? _, out int _)) + { + SetShowFilterInHeader(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.ShowFilterInHeaderEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowLabelTextUtf8, out IJsonDocument? _, out int _)) + { + SetShowLabelText(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.ShowLabelTextEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowLineItemDetailUtf8, out IJsonDocument? _, out int _)) + { + SetShowLineItemDetail(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.FlagForShowLineItemDetailInListAndTableCard.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowRefreshUtf8, out IJsonDocument? _, out int _)) + { + SetShowRefresh(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.ShowRefreshEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowSortingInHeaderUtf8, out IJsonDocument? _, out int _)) + { + SetShowSortingInHeader(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.ShowSortingInHeaderEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ChartPropertiesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.CardSetting.ChartPropertiesEntity.Mutable __corvusChartProperties)) + { + __corvusChartProperties.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ObjectStreamCardsSettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ObjectStreamCardsSettingsDef.Mutable __corvusObjectStreamCardsSettings)) + { + __corvusObjectStreamCardsSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.NavigationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.NavigationEntity.cs index 38fe128cecb..758e4af70c6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.NavigationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.NavigationEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public NavigationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheAnnotationPath.cs index 66a49f3243d..9ca47633495 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheCategoryOfTheCardUsedInTheCardHeader.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheCategoryOfTheCardUsedInTheCardHeader.cs index 04a795ed210..5b6081e7c50 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheCategoryOfTheCardUsedInTheCardHeader.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheCategoryOfTheCardUsedInTheCardHeader.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheCategoryOfTheCardUsedInTheCardHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheChartAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheChartAnnotationPath.cs index b496a1219da..00b74b9034f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheChartAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheChartAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheChartAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDataPointAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDataPointAnnotationPath.cs index 1360fdee2f8..c2f553200d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDataPointAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDataPointAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheDataPointAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs index 89cf453881a..e97d94ff181 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheDynamicSubtitleAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheEntitySetThatWillBeDisplayedInThisCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheEntitySetThatWillBeDisplayedInThisCard.cs index 32552de5bd8..aa17186e37e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheEntitySetThatWillBeDisplayedInThisCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheEntitySetThatWillBeDisplayedInThisCard.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheEntitySetThatWillBeDisplayedInThisCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheIdentificationAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheIdentificationAnnotationPath.cs index 661c9449ef7..08b3295ff3a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheIdentificationAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheIdentificationAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheIdentificationAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheKpiAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheKpiAnnotationPath.cs index bbc93b1c620..3091ccc0661 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheKpiAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheKpiAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheKpiAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThePresentationAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThePresentationAnnotationPath.cs index 8d64a10a19a..12835a2d69b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThePresentationAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThePresentationAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsThePresentationAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionAnnotationPath.cs index 13f23b6a000..2c6909ceca7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheSelectionAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionPresentationAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionPresentationAnnotationPath.cs index 67e9bcab777..401bc8caf1e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionPresentationAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSelectionPresentationAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheSelectionPresentationAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSortOrderForTheEntitySet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSortOrderForTheEntitySet.cs index 34fb95fef5b..c4c2f4e3390 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSortOrderForTheEntitySet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheSortOrderForTheEntitySet.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheSortOrderForTheEntitySet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheUserDefinedStringInPlaceholderCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheUserDefinedStringInPlaceholderCard.cs index cf9eeeb4c0e..cc17087908d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheUserDefinedStringInPlaceholderCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsTheUserDefinedStringInPlaceholderCard.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheUserDefinedStringInPlaceholderCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThingsLikePeopleNumberOfItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThingsLikePeopleNumberOfItems.cs index 11225cb177e..0aac0b7ae4b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThingsLikePeopleNumberOfItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.RepresentsThingsLikePeopleNumberOfItems.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsThingsLikePeopleNumberOfItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowFilterInHeaderEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowFilterInHeaderEntity.cs index c294327de74..de33a1f81bf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowFilterInHeaderEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowFilterInHeaderEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShowFilterInHeaderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowLabelTextEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowLabelTextEntity.cs index b256d7272bb..8ac57f1d55d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowLabelTextEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowLabelTextEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShowLabelTextEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowRefreshEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowRefreshEntity.cs index 34f2030fa71..9fef1ce4345 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowRefreshEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowRefreshEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShowRefreshEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowSortingInHeaderEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowSortingInHeaderEntity.cs index 1492edf087e..22a5ff6f9fb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowSortingInHeaderEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.ShowSortingInHeaderEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShowSortingInHeaderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.SubTitleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.SubTitleEntity.cs index b10c0cd88a4..e64adbaaf09 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.SubTitleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.SubTitleEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public SubTitleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.TitleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.TitleEntity.cs index 58bac1c696d..9f1882d6746 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.TitleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.TitleEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TitleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.cs index 496014e0319..eded00562a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CardSetting.cs @@ -1103,6 +1103,12 @@ private void CheckValidInstance() public CardSetting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.Mutable.cs index 536bc8a7c3d..1945b5090db 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.Mutable.cs @@ -205,6 +205,31 @@ public bool RemoveShortcut() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.ShortcutEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.ShortcutEntity.cs index e391d59b00a..97368f18470 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.ShortcutEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.ShortcutEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ShortcutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.cs index 0d39e50a64c..a1221c27965 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Command.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public Command Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.Mutable.cs index 910ca206a16..edf8d39095b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.Mutable.cs @@ -344,6 +344,36 @@ public bool RemoveMinVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LazyUtf8, out IJsonDocument? _, out int _)) + { + SetLazy(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Component.RepresentsIndicatorToLazyLoadingComponent.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.RepresentsIndicatorToLazyLoadingComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.RepresentsIndicatorToLazyLoadingComponent.cs index b7fe3c4d616..46eeacd149b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.RepresentsIndicatorToLazyLoadingComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.RepresentsIndicatorToLazyLoadingComponent.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsIndicatorToLazyLoadingComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.cs index 6af9e612528..38c3a7a3c52 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Component.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public Component Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.Mutable.cs index e19ab4b1fd1..8e28d185010 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.Mutable.cs @@ -362,6 +362,31 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.TheNameOfTheComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.TheNameOfTheComponent.cs index 5a2e512b5ed..d3ab4a71ea9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.TheNameOfTheComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.TheNameOfTheComponent.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TheNameOfTheComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.cs index f1c2cc37b4f..f788fbfc102 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentDef.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public ComponentDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentPagesDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentPagesDef.cs index dfbcc863252..5ec5d23740f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentPagesDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentPagesDef.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public ComponentPagesDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.LazyEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.LazyEntity.cs index fa173735845..992cb9bd1c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.LazyEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.LazyEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public LazyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.Mutable.cs index e65a7b87d59..80286c257fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.Mutable.cs @@ -464,6 +464,36 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LazyUtf8, out IJsonDocument? _, out int _)) + { + SetLazy(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ComponentUsages.LazyEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.RepresentsNameOfReuseComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.RepresentsNameOfReuseComponent.cs index 8ab60782a2b..09fb93e77c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.RepresentsNameOfReuseComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.RepresentsNameOfReuseComponent.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsNameOfReuseComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.cs index 70b5a8d8ab1..447c432e308 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ComponentUsages.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public ComponentUsages Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.ConfigArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.ConfigArray.cs index 08f5d33aa10..b0b61f64349 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.ConfigArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.ConfigArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Config public readonly partial struct ConfigArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ConfigArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.cs index 10b5bbff122..7cf7628fa39 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Config.cs @@ -624,6 +624,12 @@ private void CheckValidInstance() public Config Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationBasicDataType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationBasicDataType.cs index 273f322032b..19d1b056371 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationBasicDataType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationBasicDataType.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ConfigurationBasicDataType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.Mutable.cs index 0004e2c2472..9907ecdbe3a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.Mutable.cs @@ -241,6 +241,37 @@ public bool RemoveDataValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.cs index 7be7a922dde..f23c905e040 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationCsrfToken.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public ConfigurationCsrfToken Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.Mutable.cs index b0f0c6be087..0fa50f39f3d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.Mutable.cs @@ -403,6 +403,31 @@ public bool RemoveName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.cs index 58d49af8312..ad7bc357f7d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationDestinations.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public ConfigurationDestinations Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.Mutable.cs index 88393b4500a..efee125e905 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.Mutable.cs @@ -271,6 +271,31 @@ public bool RemoveTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.cs index 229def5c405..95851db042b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterItem.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ConfigurationFilterItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.DeterminesWhetherTheFilterIsVisible.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.DeterminesWhetherTheFilterIsVisible.cs index 22eab3a35d4..8d07aaea374 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.DeterminesWhetherTheFilterIsVisible.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.DeterminesWhetherTheFilterIsVisible.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DeterminesWhetherTheFilterIsVisible Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.Mutable.cs index 1df5176a4c4..96cba08c8fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.Mutable.cs @@ -638,6 +638,43 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.Mutable __corvusValue)) + { + __corvusValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.OptionsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.OptionsEntity.cs index e40a8bc8c6c..3210d4c5bb6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.OptionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.OptionsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OptionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.cs index 6be0ffc5da8..c404ed44fe0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.OptionsEntityArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ConfigurationFilterTypeDateRange public readonly partial struct OptionsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public OptionsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.OneOf0Entity.cs index 6ccb2c67b6c..717afc27991 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.OneOf0Entity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.cs index df4dafdd9a0..370d9cb91fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.TheTypeOfTheFilter.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.Mutable.cs index 89a70638adf..fe8fb15978b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.Mutable.cs @@ -304,6 +304,31 @@ public bool RemoveValues() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.cs index bae2fec159b..bc113179af5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.ValueEntity.cs @@ -305,6 +305,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.cs index 6739509e551..1c2c082f121 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeDateRange.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public ConfigurationFilterTypeDateRange Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.DeterminesWhetherTheFilterIsVisible.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.DeterminesWhetherTheFilterIsVisible.cs index 34af36e2b82..6e76adc997f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.DeterminesWhetherTheFilterIsVisible.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.DeterminesWhetherTheFilterIsVisible.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DeterminesWhetherTheFilterIsVisible Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.Mutable.cs index 7f1b38a3146..0c4817d9a4c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.Mutable.cs @@ -571,6 +571,37 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.OneOf0Entity.cs index 6899cd68334..9e0aef676f9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.OneOf0Entity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.cs index fe2dd5784ab..6231ecfbb5b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.TheTypeOfTheFilter.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.cs index f7e0bf1509e..b9a257a1e10 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSearch.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public ConfigurationFilterTypeSearch Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.ConfigurationFilterItemArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.ConfigurationFilterItemArray.cs index 765d2468802..c1646d050ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.ConfigurationFilterItemArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.ConfigurationFilterItemArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ConfigurationFilterTypeSelect public readonly partial struct ConfigurationFilterItemArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ConfigurationFilterItemArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.DeterminesWhetherTheFilterIsVisible.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.DeterminesWhetherTheFilterIsVisible.cs index 92d017d34c9..0114460fe1f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.DeterminesWhetherTheFilterIsVisible.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.DeterminesWhetherTheFilterIsVisible.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DeterminesWhetherTheFilterIsVisible Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.Mutable.cs index 1df9e84e9a7..91cb9cb47e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.Mutable.cs @@ -735,6 +735,43 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.Mutable __corvusItemValue)) + { + __corvusItemValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.Mutable.cs index f8d8338b009..c5951fa1bb0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.Mutable.cs @@ -369,6 +369,42 @@ public void SetTemplate(in Corvus.Ui5ManifestBenchmark.Current.Ui5Mani _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PathUtf8, out IJsonDocument? _, out int _)) + { + SetPath(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.PathEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TemplateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ConfigurationFilterItem.Mutable __corvusTemplate)) + { + __corvusTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.PathEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.PathEntity.cs index 14c1b4c85fa..474d0ab8be1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.PathEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.PathEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public PathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.cs index ab02b24aa3f..1ddd8d9c750 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.RequiredTemplate.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public RequiredTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.OneOf0Entity.cs index de1e5f5f22a..20c2a38478c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.OneOf0Entity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.cs index 328002ddde9..bb8e5a13aca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.TheTypeOfTheFilter.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.cs index b6f0742b41e..d17e233e65f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationFilterTypeSelect.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public ConfigurationFilterTypeSelect Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.Mutable.cs index 93a600bd63c..d3ee6ebf8fb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.Mutable.cs @@ -403,6 +403,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.cs index 2271f37c8ca..96013ac7f9f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationNoData.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public ConfigurationNoData Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.Mutable.cs index b7d02ddeb4b..269488b3d4c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.Mutable.cs @@ -442,6 +442,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.cs index dcf2d1f10aa..08aa9262fcd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ConfigurationParameter.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public ConfigurationParameter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionArray.cs index 9b4b8bb31b8..ec130111dc6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeAnalytical public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.OneOf0Entity.cs index 870049f2677..9b7079de81d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.cs index 3c81fd46e85..c711f9aae79 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ActionableAreaEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public ActionableAreaEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalDimensionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalDimensionArray.cs index e7ebc829cab..3c1682d382e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalDimensionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalDimensionArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ContentTypeAnalytical public readonly partial struct ContentTypeAnalyticalDimensionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalDimensionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalFieldArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalFieldArray.cs index bad9801ca84..1f021e51f81 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalFieldArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalFieldArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeAnalytical public readonly partial struct ContentTypeAnalyticalFieldArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalFieldArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalMeasureArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalMeasureArray.cs index 863d5a950c7..39a37c09a81 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalMeasureArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ContentTypeAnalyticalMeasureArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ContentTypeAnalytical public readonly partial struct ContentTypeAnalyticalMeasureArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalMeasureArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.Mutable.cs index 121ed8d9695..c0f2b584831 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.Mutable.cs @@ -447,6 +447,49 @@ public bool RemoveValueAxisText() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CategoryAxisTextUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalyticalAxisText.Mutable __corvusCategoryAxisText)) + { + __corvusCategoryAxisText.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataLabelUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.Mutable __corvusDataLabel)) + { + __corvusDataLabel.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueAxisTextUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalyticalAxisText.Mutable __corvusValueAxisText)) + { + __corvusValueAxisText.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.cs index 44fa2b5f4cc..ff13b82a52d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public DeprecatedDescribesThePlotAreaProperties Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.Mutable.cs index d5d0aca73ae..55f99c1cf63 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.Mutable.cs @@ -339,6 +339,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.OneOf0Entity.cs index 51566acb37d..efe79e0f374 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.OneOf0Entity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.cs index 197070db9da..e2c54af0394 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheTitleAlignment.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public RepresentsTheTitleAlignment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.OneOf0Entity.cs index fa1b1f8909d..a6d04abb995 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.OneOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.cs index 6f9c7b7d91b..015fb022701 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.RepresentsTheVisibilityStateOfTheTitle.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public RepresentsTheVisibilityStateOfTheTitle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.cs index 340de00a9dc..1b79bfd9832 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public DeprecatedRepresentsTitleAttributes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ExperimentalChartConfiguration.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ExperimentalChartConfiguration.cs index 1ae2c59cbb0..a1f813237c4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ExperimentalChartConfiguration.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.ExperimentalChartConfiguration.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public ExperimentalChartConfiguration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.Mutable.cs index f367ac04acb..a2ee9a45f71 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.Mutable.cs @@ -1474,6 +1474,61 @@ public bool RemoveTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LegendUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalyticalLegend.Mutable __corvusLegend)) + { + __corvusLegend.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PlotAreaUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedDescribesThePlotAreaProperties.Mutable __corvusPlotArea)) + { + __corvusPlotArea.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PopoverUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.Mutable __corvusPopover)) + { + __corvusPopover.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TitleUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalytical.DeprecatedRepresentsTitleAttributes.Mutable __corvusTitle)) + { + __corvusTitle.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.OneOf0Entity.cs index 4eb76fc76a0..7a506ed8993 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.OneOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.cs index 63dc71ee399..878f0f891bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.ActiveEntity.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public ActiveEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.Mutable.cs index 32f814e69d1..f80cfe7ab98 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.Mutable.cs @@ -207,6 +207,31 @@ public bool RemoveActive() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.cs index 7ecb485d6c2..2bde51637e7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.PopoverEntity.cs @@ -294,6 +294,12 @@ private void CheckValidInstance() public PopoverEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.TheTypeOfTheChart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.TheTypeOfTheChart.cs index e817bef1121..8d5d46cfcb3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.TheTypeOfTheChart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.TheTypeOfTheChart.cs @@ -347,6 +347,12 @@ private void CheckValidInstance() public TheTypeOfTheChart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.cs index c8218c38707..aa577ec35a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalytical.cs @@ -571,6 +571,12 @@ private void CheckValidInstance() public ContentTypeAnalytical Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.Mutable.cs index aa6dfd33a06..88d2b4808f7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.Mutable.cs @@ -205,6 +205,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.cs index e6805f91236..860b92c6cf8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalAxisText.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalAxisText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.Mutable.cs index f96d05ab2ec..8f39ef5a3ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.Mutable.cs @@ -271,6 +271,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.cs index 5057df9e081..97ec5479c5f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDataLabel.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalDataLabel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.OneOf0Entity.cs index ac863a1ea13..8db58a72d75 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.cs index c5c6fa2d1b5..254187c337c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.DataTypeEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DataTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.Mutable.cs index 4b4e325face..9e5b608ef19 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.Mutable.cs @@ -469,6 +469,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.cs index 3938d6f27bd..ee4f6396e5d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalDimension.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalDimension Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.JsonStringArray.cs index 147e34d5548..0db266efea0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeAnalyticalField public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.Mutable.cs index 8f4b6940f18..8f421ff369c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.Mutable.cs @@ -373,6 +373,31 @@ public bool RemoveValues() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.OneOf0Entity.cs index 60a9ed9d5c0..13583319bb2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.OneOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.cs index 93981b8a5e0..3400d2163f2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.TheTypeOfTheFeed.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheFeed Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.cs index ff4e60e369a..1ff61b9e3f6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalField.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalField Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.OneOf0Entity.cs index 7a704ecb12b..7c5eb9de5cc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.cs index 07da624b91f..4b03e5734a9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesHowTheLegendWillBeAligned.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DefinesHowTheLegendWillBeAligned Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.OneOf0Entity.cs index 129d1cee617..2f483c3a116 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.cs index 26dd834e693..140a00b0626 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.DefinesWhereTheLegendWillBePositioned.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DefinesWhereTheLegendWillBePositioned Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.Mutable.cs index 1eedc433ec5..deeb099e2d1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.cs index 82be32a634c..d0f842999a1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalLegend.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalLegend Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.Mutable.cs index 326a5a7559f..c091e25f140 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.cs index 2d4025b6489..cfa330dc7b2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticalMeasure.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public ContentTypeAnalyticalMeasure Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.ActionArray.cs index 89f7bcc5fd5..21d2f8fef9b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeAnalyticsCloud public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.Mutable.cs index aa67bd49d06..859b1c57de2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.Mutable.cs @@ -511,6 +511,37 @@ public bool RemoveOptions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.OptionsOfTheChart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.OptionsOfTheChart.cs index 876c8880a77..740c448fb98 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.OptionsOfTheChart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.OptionsOfTheChart.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public OptionsOfTheChart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.cs index 0faa2b25dd4..e2362c4c8b3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeAnalyticsCloud.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public ContentTypeAnalyticsCloud Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.DateEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.DateEntity.cs index 9814e0a7949..26ef199ff96 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.DateEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.DateEntity.cs @@ -347,6 +347,12 @@ private void CheckValidInstance() public DateEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.ActionArray.cs index bac824266e4..c6e68b26c12 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.ActionArray.cs @@ -30,11 +30,13 @@ public readonly partial struct MoreItemsEntity public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.Mutable.cs index 0c279d846cb..e169d47e7b4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.Mutable.cs @@ -316,6 +316,31 @@ public bool RemoveActions() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.cs index 97241b0d915..6d96743c691 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public MoreItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.Mutable.cs index 66343c83a2c..0c31bfd8a9b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.Mutable.cs @@ -913,6 +913,61 @@ public bool RemoveSpecialDate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendarItem.Mutable __corvusItemValue)) + { + __corvusItemValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LegendItemUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendarLegendItem.Mutable __corvusLegendItem)) + { + __corvusLegendItem.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MoreItemsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendar.MoreItemsEntity.Mutable __corvusMoreItems)) + { + __corvusMoreItems.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SpecialDateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendarSpecialDate.Mutable __corvusSpecialDate)) + { + __corvusSpecialDate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfItemsDisplayed.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfItemsDisplayed.cs index eabd8794f1a..5bbe5ca2c93 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfItemsDisplayed.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfItemsDisplayed.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsNumberOfItemsDisplayed Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfLegendItemsDisplayed.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfLegendItemsDisplayed.cs index 933d0b07c80..b3caf532ff4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfLegendItemsDisplayed.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.RepresentsNumberOfLegendItemsDisplayed.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsNumberOfLegendItemsDisplayed Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.TheTextShownWhenThereAreNoItemsForTheSelectedDay.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.TheTextShownWhenThereAreNoItemsForTheSelectedDay.cs index c71ce7d67ae..141a914cec1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.TheTextShownWhenThereAreNoItemsForTheSelectedDay.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.TheTextShownWhenThereAreNoItemsForTheSelectedDay.cs @@ -347,6 +347,12 @@ private void CheckValidInstance() public TheTextShownWhenThereAreNoItemsForTheSelectedDay Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.cs index 025fbc29b6c..d021f94d59a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendar.cs @@ -460,6 +460,12 @@ private void CheckValidInstance() public ContentTypeCalendar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.Mutable.cs index 90b41094fdd..895b8e64be6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.Mutable.cs @@ -307,6 +307,37 @@ public bool RemoveTemplate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TemplateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendarItemTemplate.Mutable __corvusTemplate)) + { + __corvusTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.cs index bc1b2cf6433..2732a887d2c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItem.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ContentTypeCalendarItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.ActionArray.cs index bdef0bb7e21..e648979c82c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeCalendarItemTemplate public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.Mutable.cs index 6b59a128752..f59cd3b372e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.Mutable.cs @@ -673,6 +673,37 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.SimpleIcon.Mutable __corvusIcon)) + { + __corvusIcon.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.OneOf0Entity.cs index 5a13b2a8b58..8749ba59a4b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.cs index 75e3eea9dc2..d77566848b4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTypeOfTheItemOneOfTheTypesDefinedInTheLegend Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.cs index 873580f47c2..0a08ef79ed1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarItemTemplate.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public ContentTypeCalendarItemTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.Mutable.cs index 97a4cf7103c..c934d17bd7b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.Mutable.cs @@ -307,6 +307,37 @@ public bool RemoveTemplate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TemplateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.Mutable __corvusTemplate)) + { + __corvusTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.cs index 0fad1d9cda4..81a760ef5e0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItem.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ContentTypeCalendarLegendItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.Mutable.cs index d9bbc239b1b..600b0c06911 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.OneOf0Entity.cs index ea1649ed839..f58dca81ea7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.cs index 819a12480e0..aee5a14c1dc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.TypeEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.cs index 7e9991fe78a..0777b94901b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarLegendItemTemplate.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public ContentTypeCalendarLegendItemTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.Mutable.cs index 71418a64e64..091efafa391 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.Mutable.cs @@ -307,6 +307,37 @@ public bool RemoveTemplate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TemplateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.Mutable __corvusTemplate)) + { + __corvusTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.cs index ef86f4b00c4..990fcf01b7c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDate.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ContentTypeCalendarSpecialDate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.Mutable.cs index 18f733e3054..70c2033f80c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.OneOf0Entity.cs index 885d6ae8c9f..e82014e1eec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.cs index de930aa8305..f3924ec6044 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.TypeEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.cs index b2602ae9693..04290f90738 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeCalendarSpecialDateTemplate.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public ContentTypeCalendarSpecialDateTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.Mutable.cs index ca6429594de..46061e52538 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.Mutable.cs @@ -205,6 +205,31 @@ public bool RemoveMinHeight() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.cs index d487e8477bf..437e2a09933 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeComponent.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public ContentTypeComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.Mutable.cs index ac4fca5f816..329d4bd6d23 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.Mutable.cs @@ -577,6 +577,49 @@ public bool RemoveMinItems() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GroupValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Group.Mutable __corvusGroupValue)) + { + __corvusGroupValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeListItem.Mutable __corvusItemValue)) + { + __corvusItemValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsNumberOfItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsNumberOfItems.cs index b3ad5c9a0bd..b96edc48948 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsNumberOfItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsNumberOfItems.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsNumberOfItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsTheMinimumExpectedNumberOfItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsTheMinimumExpectedNumberOfItems.cs index 33a4060f1d7..57351b50af9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsTheMinimumExpectedNumberOfItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.RepresentsTheMinimumExpectedNumberOfItems.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsTheMinimumExpectedNumberOfItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.cs index fdf62c0b217..96028ca733d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeList.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public ContentTypeList Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionArray.cs index e5bd9547c77..e395593c8ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeListItem public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionsStripItemArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionsStripItemArray.cs index 5547172f303..0885dacacab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionsStripItemArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ActionsStripItemArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeListItem public readonly partial struct ActionsStripItemArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionsStripItemArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ContentTypeListItemValueStateItemArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ContentTypeListItemValueStateItemArray.cs index d201fd3537f..52a5cfce51b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ContentTypeListItemValueStateItemArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.ContentTypeListItemValueStateItemArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeListItem public readonly partial struct ContentTypeListItemValueStateItemArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ContentTypeListItemValueStateItemArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.OneOf0Entity.cs index 0f59f279d45..3030e2f53d0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.cs index 1291e1b713f..c7679a49a88 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.DefinesTheLayoutTypeOfTheAttributes.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DefinesTheLayoutTypeOfTheAttributes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.Mutable.cs index 60d3753a38d..86c8ac20af7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.Mutable.cs @@ -1156,6 +1156,43 @@ public bool RemoveTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Icon.Mutable __corvusIconValue)) + { + __corvusIconValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InfoUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeListItemValueStateItem.Mutable __corvusInfo)) + { + __corvusInfo.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheDescriptionOfTheItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheDescriptionOfTheItem.cs index 089c6e19b5f..bd9e34b1f7b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheDescriptionOfTheItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheDescriptionOfTheItem.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public TheDescriptionOfTheItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheHighlightStateOfTheItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheHighlightStateOfTheItem.cs index f412ce05ed7..cfbc9096990 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheHighlightStateOfTheItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheHighlightStateOfTheItem.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheHighlightStateOfTheItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheTitleOfTheItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheTitleOfTheItem.cs index 27df216ef50..c7464999a31 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheTitleOfTheItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.TheTitleOfTheItem.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public TheTitleOfTheItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.cs index bb7f0d78431..2c70b0a8868 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItem.cs @@ -505,6 +505,12 @@ private void CheckValidInstance() public ContentTypeListItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.DefinesIfADefaultStateIconIsShown.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.DefinesIfADefaultStateIconIsShown.cs index a9a8129909b..5775661b0ab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.DefinesIfADefaultStateIconIsShown.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.DefinesIfADefaultStateIconIsShown.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DefinesIfADefaultStateIconIsShown Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.Mutable.cs index 4b734b95910..659f77660de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.Mutable.cs @@ -535,6 +535,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.TheStateOfTheField.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.TheStateOfTheField.cs index 6d0f0539d15..96a1097cb41 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.TheStateOfTheField.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.TheStateOfTheField.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheStateOfTheField Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.VisibilityOfTheItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.VisibilityOfTheItem.cs index 8ef9706ff29..3b33a87003f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.VisibilityOfTheItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.VisibilityOfTheItem.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public VisibilityOfTheItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.cs index 98befeeea8d..821dec0b802 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeListItemValueStateItem.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public ContentTypeListItemValueStateItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ActionArray.cs index b516f64795e..c41f18dc032 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeObject public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ContentTypeObjectGroupArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ContentTypeObjectGroupArray.cs index 98f6309003b..7ff5ced6937 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ContentTypeObjectGroupArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.ContentTypeObjectGroupArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeObject public readonly partial struct ContentTypeObjectGroupArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ContentTypeObjectGroupArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.Mutable.cs index 255157b24e5..db0ca27ee1f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.Mutable.cs @@ -547,6 +547,42 @@ public bool RemoveHasData() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HasDataUtf8, out IJsonDocument? _, out int _)) + { + SetHasData(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObject.RepresentsFlagForNoData.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.RepresentsFlagForNoData.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.RepresentsFlagForNoData.cs index 489e80f4967..d02afaf81cc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.RepresentsFlagForNoData.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.RepresentsFlagForNoData.cs @@ -501,6 +501,12 @@ private void CheckValidInstance() public RepresentsFlagForNoData Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.cs index 67216addeaa..ab91e3dca0a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObject.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public ContentTypeObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ContentTypeObjectItemArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ContentTypeObjectItemArray.cs index c7d641f44d4..8c1bdd29265 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ContentTypeObjectItemArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ContentTypeObjectItemArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeObjectGroup public readonly partial struct ContentTypeObjectItemArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ContentTypeObjectItemArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ExperimentalAlignmentOfTheGroup.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ExperimentalAlignmentOfTheGroup.cs index 6a5be63c790..3c6c5ef5a49 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ExperimentalAlignmentOfTheGroup.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.ExperimentalAlignmentOfTheGroup.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ExperimentalAlignmentOfTheGroup Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.LabelWrappingEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.LabelWrappingEntity.cs index 493ae06f475..ab20c39fbac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.LabelWrappingEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.LabelWrappingEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public LabelWrappingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.Mutable.cs index 573dda57431..01a3d56690f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.Mutable.cs @@ -558,6 +558,46 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AlignmentUtf8, out IJsonDocument? _, out int _)) + { + SetAlignment(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectGroup.ExperimentalAlignmentOfTheGroup.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LabelWrappingUtf8, out IJsonDocument? _, out int _)) + { + SetLabelWrapping(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectGroup.LabelWrappingEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TitleMaxLinesUtf8, out IJsonDocument? _, out int _)) + { + SetTitleMaxLines(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectGroup.TitleMaxLinesEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.TitleMaxLinesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.TitleMaxLinesEntity.cs index 2cb6ab063a7..427d3c892eb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.TitleMaxLinesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.TitleMaxLinesEntity.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public TitleMaxLinesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.cs index f9ce47dc076..644959c56e4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectGroup.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public ContentTypeObjectGroup Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ActionArray.cs index c35a82eab4d..ff452800abf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeObjectItem public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.Mutable.cs index 2d4f5f7b96f..a1a8c68fc5a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.Mutable.cs @@ -296,6 +296,42 @@ public void SetTemplate(in Corvus.Ui5ManifestBenchmark.Current.Ui5Mani _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PathUtf8, out IJsonDocument? _, out int _)) + { + SetPath(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.PathEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TemplateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.Mutable __corvusTemplate)) + { + __corvusTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.PathEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.PathEntity.cs index 431415ab378..6bd7b93c9d3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.PathEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.PathEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public PathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.cs index 580aa2f5b54..08b2a0f9929 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BindingInfoForComboBoxItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ContentTypeObjectItemValidationArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ContentTypeObjectItemValidationArray.cs index 931d8a169ff..fdad72049d0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ContentTypeObjectItemValidationArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ContentTypeObjectItemValidationArray.cs @@ -23,11 +23,13 @@ public readonly partial struct ContentTypeObjectItem public readonly partial struct ContentTypeObjectItemValidationArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ContentTypeObjectItemValidationArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesIfADefaultStateIconIsShown.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesIfADefaultStateIconIsShown.cs index 65d25a97370..e8cd40dbe9a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesIfADefaultStateIconIsShown.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesIfADefaultStateIconIsShown.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DefinesIfADefaultStateIconIsShown Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesWhetherTheColonNextToTheLabelIsShown.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesWhetherTheColonNextToTheLabelIsShown.cs index f64ca3f5e20..ac3a41db25d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesWhetherTheColonNextToTheLabelIsShown.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.DefinesWhetherTheColonNextToTheLabelIsShown.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DefinesWhetherTheColonNextToTheLabelIsShown Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.OneOf0Entity.cs index bb5a0f5f1c7..0304c54f4fd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.cs index a27bf380f8c..8e08970f94e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheAlignmentOfTheSideIndicators.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public ExperimentalTheAlignmentOfTheSideIndicators Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.OneOf0Entity.cs index d766f7234fe..34fdec65c1d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.cs index 11cdd4b5af9..d73ad616c5b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.ExperimentalTheSizeOfTheIconsInAnIconGroup.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public ExperimentalTheSizeOfTheIconsInAnIconGroup Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.OneOf0Entity.cs index 3b5572fb8ad..7a29b58db38 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.cs index 584cb8a0cca..07ab6b00474 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.FullWidthEntity.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public FullWidthEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.HeaderTypeNumericSideIndicatorArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.HeaderTypeNumericSideIndicatorArray.cs index 73ff5c47b50..7e6ec3f8604 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.HeaderTypeNumericSideIndicatorArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.HeaderTypeNumericSideIndicatorArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeObjectItem public readonly partial struct HeaderTypeNumericSideIndicatorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public HeaderTypeNumericSideIndicatorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.MaximumNumberOfLines.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.MaximumNumberOfLines.cs index 7b2faa60bc7..b1c72c2db24 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.MaximumNumberOfLines.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.MaximumNumberOfLines.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public MaximumNumberOfLines Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.Mutable.cs index 89333bfbe40..1637b6d6fd0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.Mutable.cs @@ -2648,6 +2648,60 @@ public bool RemoveVisualMode() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StateValueUtf8, out IJsonDocument? _, out int _)) + { + SetStateValue(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.State.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Icon.Mutable __corvusIconValue)) + { + __corvusIconValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectItem.BindingInfoForComboBoxItems.Mutable __corvusItemValue)) + { + __corvusItemValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MainIndicatorUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.Mutable __corvusMainIndicator)) + { + __corvusMainIndicator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TemplateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.Mutable __corvusTemplate)) + { + __corvusTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.Mutable.cs index a512d440a82..bfafe9d2ca5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.Mutable.cs @@ -306,6 +306,31 @@ public bool RemoveValues() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.cs index 619053488eb..f5b538ad1d1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.OneOf2Entity.cs @@ -307,6 +307,12 @@ private void CheckValidInstance() public OneOf2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.cs index eb3c0e5415f..dddc9d5f127 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.RepresentsTheTextWhichIsAssociatedWithTheLabel.cs @@ -565,6 +565,12 @@ private void CheckValidInstance() public RepresentsTheTextWhichIsAssociatedWithTheLabel Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TargetEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TargetEntity.cs index 08811a30d26..90c98f14641 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TargetEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TargetEntity.cs @@ -454,6 +454,12 @@ private void CheckValidInstance() public TargetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.OneOf0Entity.cs index 24c02f82d27..57dfb55e214 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.OneOf0Entity.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.cs index f47fba01fbb..326122d3d32 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TheNumberOfDisplayedSymbolsForRatingIndicator.cs @@ -512,6 +512,12 @@ private void CheckValidInstance() public TheNumberOfDisplayedSymbolsForRatingIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.OneOf0Entity.cs index 42d6a3020f0..1dddff8ff96 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.cs index 747a8394bac..afc3f39ab72 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.TypeEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.OneOf0Entity.cs index c72845105f3..cea24d29d9f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.cs index 1a81beb05f9..539553d8e9c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.VisualModeEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public VisualModeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.cs index 93cbdcf8c55..88dc4c89c9f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItem.cs @@ -971,6 +971,12 @@ private void CheckValidInstance() public ContentTypeObjectItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.Mutable.cs index eaec0df34f1..b8f56090e44 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.Mutable.cs @@ -271,6 +271,31 @@ public bool RemoveTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.cs index 6cfd2dc8ef1..5fdd3a3acde 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemComboBoxItemTemplate.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ContentTypeObjectItemComboBoxItemTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.Mutable.cs index f24b757b8eb..31d09829a2a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.Mutable.cs @@ -403,6 +403,31 @@ public bool RemoveText() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.cs index 9abd3b435ff..45603641791 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public ContentTypeObjectItemIconGroupIcon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.ActionArray.cs index 42db643da2b..045dcd621e7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeObjectItemIconGroupTemplate public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.Mutable.cs index d76f3a03258..a8cb5c7bcff 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.Mutable.cs @@ -330,6 +330,37 @@ public void SetIcon(in Corvus.Ui5ManifestBenchmark.Current.Ui5Manifest _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObjectItemIconGroupIcon.Mutable __corvusIcon)) + { + __corvusIcon.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.cs index 2ebb1162af9..0bc60dea662 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemIconGroupTemplate.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ContentTypeObjectItemIconGroupTemplate Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.Mutable.cs index 4fc582c8eb8..e8dab91376d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.Mutable.cs @@ -464,6 +464,31 @@ public bool RemoveUnit() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.OneOf0Entity.cs index 84fc45b7f3f..41fd9939969 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.cs index 5481b5625e8..fc33ab0b801 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.SizeEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public SizeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheStateColorOfTheMainIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheStateColorOfTheMainIndicator.cs index c005f9abeb0..8cacddb7ad0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheStateColorOfTheMainIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheStateColorOfTheMainIndicator.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheStateColorOfTheMainIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs index a3489f75dc3..6ead84ee798 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.cs index 54933a62511..62e428bcadf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.TheTrendIndicatorDirection.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTrendIndicatorDirection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.cs index 790eba9c6f6..375398fef67 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemMainIndicator.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public ContentTypeObjectItemMainIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMaximumNumberOfCharacters.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMaximumNumberOfCharacters.cs index 18f7e432e6f..344bd9ee455 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMaximumNumberOfCharacters.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMaximumNumberOfCharacters.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public DefinesTheMaximumNumberOfCharacters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMinimumNumberOfCharacters.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMinimumNumberOfCharacters.cs index 07a6e0acfe8..4e587c2ce52 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMinimumNumberOfCharacters.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheMinimumNumberOfCharacters.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public DefinesTheMinimumNumberOfCharacters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.OneOf0Entity.cs index 3c326654c57..2f58dfd64d8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.cs index 1d227e1d1c9..f730d7390a4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesTheValidationType.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DefinesTheValidationType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.OneOf0Entity.cs index 6a11c6df92c..0984edd90d9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.cs index c4c52b5b0fc..5cd04566393 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheUserInputIsRequired.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public DefinesWhetherTheUserInputIsRequired Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.OneOf0Entity.cs index 95d452487e3..0410d8fff13 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.cs index 6e8aa936fad..d5497091a80 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.DefinesWhetherTheValueIsRestrictedToPredefinedOptions.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public DefinesWhetherTheValueIsRestrictedToPredefinedOptions Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.Mutable.cs index 99165f0c0b2..7ab0f675849 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.Mutable.cs @@ -667,6 +667,31 @@ public bool RemoveValidate() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.cs index 55def1cd5e5..68264bebfd1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeObjectItemValidation.cs @@ -439,6 +439,12 @@ private void CheckValidInstance() public ContentTypeObjectItemValidation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.Mutable.cs index b99b9b1c007..df230b7765f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.Mutable.cs @@ -577,6 +577,49 @@ public bool RemoveRow() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GroupValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Group.Mutable __corvusGroupValue)) + { + __corvusGroupValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RowUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.Mutable __corvusRow)) + { + __corvusRow.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsNumberOfItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsNumberOfItems.cs index 4c2fbe1be87..e2155b901a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsNumberOfItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsNumberOfItems.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsNumberOfItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsTheMinimumExpectedNumberOfItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsTheMinimumExpectedNumberOfItems.cs index 8cd94b32b6f..e336476b644 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsTheMinimumExpectedNumberOfItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.RepresentsTheMinimumExpectedNumberOfItems.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsTheMinimumExpectedNumberOfItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ActionArray.cs index b51b6a47fd7..0a78783071a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ActionArray.cs @@ -30,11 +30,13 @@ public readonly partial struct TheTemplateForAllRows public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ContentTypeTableColumnArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ContentTypeTableColumnArray.cs index 83ce8aa1607..ee21ce4a4c2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ContentTypeTableColumnArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.ContentTypeTableColumnArray.cs @@ -30,11 +30,13 @@ public readonly partial struct TheTemplateForAllRows public readonly partial struct ContentTypeTableColumnArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ContentTypeTableColumnArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.Mutable.cs index 9d44282ac75..7cf4930e66f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.Mutable.cs @@ -477,6 +477,31 @@ public bool RemoveHighlightText() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.TheHighlightStateOfTheRow.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.TheHighlightStateOfTheRow.cs index 7cd89ab9850..85a0064d878 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.TheHighlightStateOfTheRow.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.TheHighlightStateOfTheRow.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public TheHighlightStateOfTheRow Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.cs index 03446c33f15..03e2263b2d5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.TheTemplateForAllRows.cs @@ -357,6 +357,12 @@ private void CheckValidInstance() public TheTemplateForAllRows Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.cs index 6cb1e36174e..d9e3b92cbfa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTable.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public ContentTypeTable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.ActionArray.cs index bb89d7e554b..c154df7f9dd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeTableColumn public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesIfADefaultStateIconIsShown.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesIfADefaultStateIconIsShown.cs index 69a4287d346..0c361f1eff8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesIfADefaultStateIconIsShown.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesIfADefaultStateIconIsShown.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public DefinesIfADefaultStateIconIsShown Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheHorizontalAlignmentOfTheColumnContent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheHorizontalAlignmentOfTheColumnContent.cs index cdf966a2ffa..b2a00c62228 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheHorizontalAlignmentOfTheColumnContent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheHorizontalAlignmentOfTheColumnContent.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DefinesTheHorizontalAlignmentOfTheColumnContent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheStateOfTheColumn.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheStateOfTheColumn.cs index 397990e1cee..a8c50e76522 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheStateOfTheColumn.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.DefinesTheStateOfTheColumn.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public DefinesTheStateOfTheColumn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.IdentifierEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.IdentifierEntity.cs index ca3f3e05e74..ea354cdfbc6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.IdentifierEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.IdentifierEntity.cs @@ -545,6 +545,12 @@ private void CheckValidInstance() public IdentifierEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.Mutable.cs index 0c3e2ecabff..453bf215f31 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.Mutable.cs @@ -1310,6 +1310,43 @@ public bool RemoveWidth() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Icon.Mutable __corvusIconValue)) + { + __corvusIconValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ProgressIndicatorValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ProgressIndicator.Mutable __corvusProgressIndicatorValue)) + { + __corvusProgressIndicatorValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.TargetEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.TargetEntity.cs index 477a7e6201d..efeea8b30a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.TargetEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.TargetEntity.cs @@ -454,6 +454,12 @@ private void CheckValidInstance() public TargetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.cs index 4b19a51ad20..0733c24630d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTableColumn.cs @@ -587,6 +587,12 @@ private void CheckValidInstance() public ContentTypeTableColumn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.Mutable.cs index ce3e63e6d71..59225196da1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.Mutable.cs @@ -478,6 +478,43 @@ public bool RemoveMinItems() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeTimelineItem.Mutable __corvusItemValue)) + { + __corvusItemValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsNumberOfItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsNumberOfItems.cs index 7203527d8fd..7f10a4b4d4f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsNumberOfItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsNumberOfItems.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsNumberOfItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsTheMinimumExpectedNumberOfItems.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsTheMinimumExpectedNumberOfItems.cs index 9e67707e473..04c89856004 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsTheMinimumExpectedNumberOfItems.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.RepresentsTheMinimumExpectedNumberOfItems.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsTheMinimumExpectedNumberOfItems Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.cs index 2e43c3fd791..45bbadf363e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimeline.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public ContentTypeTimeline Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.ActionArray.cs index 6755b6241ee..119a2acd9ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ContentTypeTimelineItem public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.Mutable.cs index 5aabef54393..4c918f2d75a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.Mutable.cs @@ -856,6 +856,67 @@ public bool RemoveTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DateTimeValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Field.Mutable __corvusDateTimeValue)) + { + __corvusDateTimeValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DescriptionUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Field.Mutable __corvusDescription)) + { + __corvusDescription.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.SimpleIcon.Mutable __corvusIcon)) + { + __corvusIcon.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OwnerUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Field.Mutable __corvusOwner)) + { + __corvusOwner.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OwnerImageUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.Mutable __corvusOwnerImage)) + { + __corvusOwnerImage.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TitleUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Field.Mutable __corvusTitle)) + { + __corvusTitle.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.Mutable.cs index b01a70085f8..3e0254b2368 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.Mutable.cs @@ -275,6 +275,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.cs index b4edb3ad813..4723f384c13 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.TheOwnerImageOfTheTimelineItem.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public TheOwnerImageOfTheTimelineItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.cs index 9101917ca24..64efd8858af 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeTimelineItem.cs @@ -421,6 +421,12 @@ private void CheckValidInstance() public ContentTypeTimelineItem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.Mutable.cs index ae1988ee413..9071f81ec20 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.Mutable.cs @@ -439,6 +439,37 @@ public bool RemoveSrc() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.cs index 88c54f62a2e..3002c95e645 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ContentTypeWebPage.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public ContentTypeWebPage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.Mutable.cs index a60676d43ac..2288a0bb4b8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.Mutable.cs @@ -380,6 +380,37 @@ public bool RemoveManifest() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ManifestUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.Mutable __corvusManifest)) + { + __corvusManifest.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.Mutable.cs index 44b857ecc97..71aef3ac7fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.Mutable.cs @@ -316,6 +316,31 @@ public bool RemoveSapArtifact() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.cs index 5e7e3566536..421f00c8e46 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.WrapsTheChildManifest.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public WrapsTheChildManifest Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.cs index 3f219e3eaa3..0f85af36ba2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Contentitem.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public Contentitem Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.Mutable.cs index 9bbac417176..e2db5daa88e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.Mutable.cs @@ -410,6 +410,31 @@ public bool RemoveText() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.NameOfThePressHandlerForExtendedActionsInQuickView.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.NameOfThePressHandlerForExtendedActionsInQuickView.cs index 6237cffc5a2..de08a149d74 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.NameOfThePressHandlerForExtendedActionsInQuickView.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.NameOfThePressHandlerForExtendedActionsInQuickView.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public NameOfThePressHandlerForExtendedActionsInQuickView Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.TextDisplayedForExtendedActionsInQuickView.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.TextDisplayedForExtendedActionsInQuickView.cs index 5b1bfffda54..c8a3d7fe06b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.TextDisplayedForExtendedActionsInQuickView.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.TextDisplayedForExtendedActionsInQuickView.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TextDisplayedForExtendedActionsInQuickView Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.cs index dea42a3b04c..3b1de5eeb09 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.CustomActionsSetting.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public CustomActionsSetting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.Mutable.cs index fa6bcfadc10..355e4dfac5a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.Mutable.cs @@ -447,6 +447,43 @@ public bool RemoveRequestValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtensionValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Extension.Mutable __corvusExtensionValue)) + { + __corvusExtensionValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequestValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Request.Mutable __corvusRequestValue)) + { + __corvusRequestValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.TheDataToBeUsedDirectlyWithoutMakingRequests.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.TheDataToBeUsedDirectlyWithoutMakingRequests.cs index e44da97db15..1092c841d31 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.TheDataToBeUsedDirectlyWithoutMakingRequests.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.TheDataToBeUsedDirectlyWithoutMakingRequests.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public TheDataToBeUsedDirectlyWithoutMakingRequests Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.cs index 2082ffb17e1..b34505d3f2a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public ExperimentalMockDataAttributes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.Mutable.cs index 1e1990724b3..79896905882 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.Mutable.cs @@ -847,6 +847,60 @@ public bool RemoveUpdateInterval() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PathUtf8, out IJsonDocument? _, out int _)) + { + SetPath(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.ThePathFromTheJsonToBeUsedAsRoot.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtensionValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Extension.Mutable __corvusExtensionValue)) + { + __corvusExtensionValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MockDataUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.ExperimentalMockDataAttributes.Mutable __corvusMockData)) + { + __corvusMockData.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequestValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Request.Mutable __corvusRequestValue)) + { + __corvusRequestValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ServiceValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Service.Mutable __corvusServiceValue)) + { + __corvusServiceValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.TheDataToBeUsedDirectlyWithoutMakingRequests.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.TheDataToBeUsedDirectlyWithoutMakingRequests.cs index 69af16853cb..7b1c9264a2e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.TheDataToBeUsedDirectlyWithoutMakingRequests.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.TheDataToBeUsedDirectlyWithoutMakingRequests.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public TheDataToBeUsedDirectlyWithoutMakingRequests Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ThePathFromTheJsonToBeUsedAsRoot.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ThePathFromTheJsonToBeUsedAsRoot.cs index 30af6058230..0ff6357847a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ThePathFromTheJsonToBeUsedAsRoot.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.ThePathFromTheJsonToBeUsedAsRoot.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ThePathFromTheJsonToBeUsedAsRoot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.UpdateIntervalEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.UpdateIntervalEntity.cs index e00e8e0d23b..7fff515d878 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.UpdateIntervalEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.UpdateIntervalEntity.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public UpdateIntervalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.cs index 80fd400b9fb..313050f62f8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Data.cs @@ -439,6 +439,12 @@ private void CheckValidInstance() public Data Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSource.cs index 26cb9db04a4..165afe9b3b6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSource.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public DataSource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.CustomTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.CustomTypeEntity.cs index 71b6486a572..b0b6eec8ec6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.CustomTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.CustomTypeEntity.cs @@ -308,6 +308,12 @@ private void CheckValidInstance() public CustomTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.Mutable.cs index a57fad10a3b..f21d5f5025c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.Mutable.cs @@ -417,6 +417,37 @@ public void SetUriValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Setting.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.NotEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.NotEntity.cs index 1550b7d0773..bf437cc5fad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.NotEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.NotEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public NotEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.cs index dd817de3d38..cbada8ad391 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.TypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.cs index fc4959d276e..914bac7e6a5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceCustom.cs @@ -356,6 +356,12 @@ private void CheckValidInstance() public DataSourceCustom Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.CustomTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.CustomTypeEntity.cs index efd2a6d8ece..5a194669794 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.CustomTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.CustomTypeEntity.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public CustomTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.Mutable.cs index 31ebe453f8a..ac5873b5341 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.Mutable.cs @@ -423,6 +423,42 @@ public void SetUriValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypeUtf8, out IJsonDocument? _, out int _)) + { + SetType(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.DataSourceEnum.TypeEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Setting.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.TypeEntity.cs index 78de6b0375a..eef87cf2369 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.TypeEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.cs index 119a1e7451b..bd61356fb04 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DataSourceEnum.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public DataSourceEnum Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.OneOf1Entity.cs index 817750c6a83..04f516252a3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.OneOf1Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumSubTitleRowEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumSubTitleRowEntity.cs index ebac9706efb..8744cd78dee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumSubTitleRowEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumSubTitleRowEntity.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public MinimumSubTitleRowEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumTitleRowEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumTitleRowEntity.cs index 8512ea1ee05..a1385972be3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumTitleRowEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumTitleRowEntity.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public MinimumTitleRowEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.Mutable.cs index 1029af6e1cc..f0a51e32185 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.Mutable.cs @@ -449,6 +449,46 @@ public bool RemoveShowOnlyHeader() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinimumSubTitleRowUtf8, out IJsonDocument? _, out int _)) + { + SetMinimumSubTitleRow(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumSubTitleRowEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MinimumTitleRowUtf8, out IJsonDocument? _, out int _)) + { + SetMinimumTitleRow(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.MinimumTitleRowEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowOnlyHeaderUtf8, out IJsonDocument? _, out int _)) + { + SetShowOnlyHeader(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.ShowOnlyHeaderEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.ShowOnlyHeaderEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.ShowOnlyHeaderEntity.cs index 4f3d666e07d..70e4228ab24 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.ShowOnlyHeaderEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.ShowOnlyHeaderEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ShowOnlyHeaderEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.cs index f00af162c7a..28487d4062c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.RequiredColsAndRows.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public RequiredColsAndRows Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.cs index 534161048f4..cf9d9365fa8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefaultSpanDef.cs @@ -452,6 +452,12 @@ private void CheckValidInstance() public DefaultSpanDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.Mutable.cs index 75dd3f566ce..dd1e1d6e16c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.Mutable.cs @@ -315,6 +315,36 @@ public bool RemoveRetrieveStreams() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RetrieveStreamsUtf8, out IJsonDocument? _, out int _)) + { + SetRetrieveStreams(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.DefiningRequest.RepresentsIndicatorWhetherStreamsShouldBeRetrieved.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.RepresentsIndicatorWhetherStreamsShouldBeRetrieved.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.RepresentsIndicatorWhetherStreamsShouldBeRetrieved.cs index c8ede153363..7e3528ee4c0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.RepresentsIndicatorWhetherStreamsShouldBeRetrieved.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.RepresentsIndicatorWhetherStreamsShouldBeRetrieved.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsIndicatorWhetherStreamsShouldBeRetrieved Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.cs index 834d68f5385..821bbc7cef9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DefiningRequest.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public DefiningRequest Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.Mutable.cs index 6f4ac9476b8..301c6bc0135 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveTablet() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.cs index 6cad8da05fd..fb462ad61ee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.DeviceType.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public DeviceType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.Mutable.cs index da7a208902c..d5367347b66 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.Mutable.cs @@ -273,6 +273,31 @@ public void SetComponentName(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5Ma _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.RepresentsTheNameOfTheReuseComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.RepresentsTheNameOfTheReuseComponent.cs index d46f64f4158..28fe34e6e17 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.RepresentsTheNameOfTheReuseComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.RepresentsTheNameOfTheReuseComponent.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public RepresentsTheNameOfTheReuseComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.cs index d66984457c3..685e9692fcb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentName.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public RequiredComponentName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.Mutable.cs index 3b07c0c551b..a683e92ae0c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.Mutable.cs @@ -273,6 +273,31 @@ public void SetComponentUsage(scoped in Corvus.Ui5ManifestBenchmark.Current.Json _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.cs index 118959949a8..5721819d0a0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredComponentUsage.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public RequiredComponentUsage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.Mutable.cs index f094d27d671..c4d6b7140bb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.Mutable.cs @@ -304,6 +304,31 @@ public void SetEmbeddedComponents(in Corvus.Ui5ManifestBenchmark.Curre _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.cs index 4052b817d9f..528240468e4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.RequiredEmbeddedComponents.cs @@ -366,6 +366,12 @@ private void CheckValidInstance() public RequiredEmbeddedComponents Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.cs index 4f01565ee64..d25dbda30fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.AllOf1Entity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.Mutable.cs index 2c3e6fb2fca..6ec2c9b9230 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.Mutable.cs @@ -816,6 +816,31 @@ public void SetTitle(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.IdEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.IdEntity.cs index 0217c49b2ab..38e2622e0a3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.IdEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.IdEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public IdEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.Mutable.cs index b613880a9bb..0780ed2c5b3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.Mutable.cs @@ -728,6 +728,31 @@ public void SetTitle(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSc _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.RepresentsTheTitleForTheContentOfTheReuseComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.RepresentsTheTitleForTheContentOfTheReuseComponent.cs index dc1e5ccfd82..5591e583a61 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.RepresentsTheTitleForTheContentOfTheReuseComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.RepresentsTheTitleForTheContentOfTheReuseComponent.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public RepresentsTheTitleForTheContentOfTheReuseComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.cs index 126e5ec2662..6d05c88ec38 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.RequiredIdAndTitle.cs @@ -496,6 +496,12 @@ private void CheckValidInstance() public RequiredIdAndTitle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.cs index 8fc714adef7..9f824b8a18d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.AZaZ09Entity.cs @@ -584,6 +584,12 @@ private void CheckValidInstance() public AZaZ09Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.cs index 48d9298a8b9..0c6fc1dc9f5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EmbeddedComponent.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public EmbeddedComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.Mutable.cs index fe667f60112..bda071603e6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.Mutable.cs @@ -466,6 +466,31 @@ public bool RemoveTerminologies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs index c9237f98b5f..41205f658a6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public RepresentsTerminologiesWithAdditionalPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.cs index 91573b7f267..d157132992c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleName.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public RequiredBundleName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs index 17292c63534..e8e6f2fa934 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public BundleUrlRelativeToEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.Mutable.cs index ae2978068f7..ee93a49546d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.Mutable.cs @@ -532,6 +532,36 @@ public bool RemoveTerminologies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleUrlRelativeToUtf8, out IJsonDocument? _, out int _)) + { + SetBundleUrlRelativeTo(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.BundleUrlRelativeToEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs index 6e15b3c2334..f71ddf4d8e3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public RepresentsTerminologiesWithAdditionalPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.cs index ae74a9585c0..025fcb2587c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.RequiredBundleUrl.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public RequiredBundleUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.cs index b1e0d31f60e..ec95bbd3c5e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnhanceWithSetting.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public EnhanceWithSetting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnumsValueColor.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnumsValueColor.cs index b90fe8185a6..b45c6c14c54 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnumsValueColor.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.EnumsValueColor.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public EnumsValueColor Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.Mutable.cs index 12729d8cd53..be69582bf84 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.Mutable.cs @@ -296,6 +296,31 @@ public void SetMethod(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.S _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.cs index ac3de49d6e8..712ed05c21d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Extension.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public Extension Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.Mutable.cs index 593b165928a..e9b97dabf15 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.cs index 6273bd881e5..0bfd3ef84f6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Field.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public Field Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.Mutable.cs index 3c08c9d039e..845ab851011 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.Mutable.cs @@ -280,6 +280,31 @@ public bool RemoveOperation() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.cs index 0fd9a60ec20..73759be9050 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public DefaultValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.FlagToExcludeValuesFromTheDatePicker.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.FlagToExcludeValuesFromTheDatePicker.cs index 6ae949db6f7..7ec84fe3705 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.FlagToExcludeValuesFromTheDatePicker.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.FlagToExcludeValuesFromTheDatePicker.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public FlagToExcludeValuesFromTheDatePicker Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.Mutable.cs index c704fa12c66..264229fa41d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.Mutable.cs @@ -512,6 +512,42 @@ public bool RemoveSelectedValues() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExcludeUtf8, out IJsonDocument? _, out int _)) + { + SetExclude(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.FilterFieldName.FlagToExcludeValuesFromTheDatePicker.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.FilterFieldName.DefaultValueEntity.Mutable __corvusDefaultValue)) + { + __corvusDefaultValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.cs index eb0f5f28cab..5f704b7f0ef 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.FilterFieldName.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public FilterFieldName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.Mutable.cs index 737df5442bf..3be7555f610 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.Mutable.cs @@ -307,6 +307,37 @@ public bool RemoveTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OrderUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.Mutable __corvusOrder)) + { + __corvusOrder.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.Mutable.cs index fe2a7e8d471..08733d5b780 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.Mutable.cs @@ -273,6 +273,31 @@ public bool RemovePath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.OneOf0Entity.cs index b3db71daee8..10c4f40c84a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.OneOf0Entity.cs @@ -329,6 +329,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.cs index f76248451a4..33e387e0391 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.TheSortingDirectionInWhichTheGroupItemsWillBeOrdered.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public TheSortingDirectionInWhichTheGroupItemsWillBeOrdered Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.cs index 1689c0610be..e90f763a82a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.TheOrderByWhichTheGroupWillBeSorted.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public TheOrderByWhichTheGroupWillBeSorted Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.cs index 70f04274203..b755226e829 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Group.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public Group Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderType.cs index 4a61f07ae0f..83f7fcfb67e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderType.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public HeaderType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ActionArray.cs index fe9d126430a..8ec00a7d425 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct HeaderTypeDefault public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs index 4ce3ab8f1c0..993746bd847 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ExperimentalLimitTheNumberOfLinesForTheSubTitle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheTitle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheTitle.cs index 1dfa1072aa0..ee5df2f8cca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheTitle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheTitle.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ExperimentalLimitTheNumberOfLinesForTheTitle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs index b8969cb38bb..dac4340128e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.cs index 27c83dad649..28f7d93daaa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.ExperimentalVisibilityOfTheHeader.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public ExperimentalVisibilityOfTheHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.Mutable.cs index f3264433b9f..441e217f557 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.Mutable.cs @@ -949,6 +949,59 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SubTitleMaxLinesUtf8, out IJsonDocument? _, out int _)) + { + SetSubTitleMaxLines(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheSubTitle.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TitleMaxLinesUtf8, out IJsonDocument? _, out int _)) + { + SetTitleMaxLines(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.HeaderTypeDefault.ExperimentalLimitTheNumberOfLinesForTheTitle.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.IconWithoutSize.Mutable __corvusIcon)) + { + __corvusIcon.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatusValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Status.Mutable __corvusStatusValue)) + { + __corvusStatusValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.RepresentsTheTypeOfTheHeader.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.RepresentsTheTypeOfTheHeader.cs index b36e76535e4..89f2a4602c8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.RepresentsTheTypeOfTheHeader.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.RepresentsTheTypeOfTheHeader.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.cs index 689cf67864c..9b521015aa0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeDefault.cs @@ -487,6 +487,12 @@ private void CheckValidInstance() public HeaderTypeDefault Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ActionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ActionArray.cs index eeeec237abd..f4b19785ca0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ActionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ActionArray.cs @@ -28,11 +28,13 @@ public readonly partial struct HeaderTypeNumeric public readonly partial struct ActionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ActionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheDetailsText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheDetailsText.cs index fdaa0efd619..3c85e805fae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheDetailsText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheDetailsText.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ExperimentalLimitTheNumberOfLinesForTheDetailsText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs index dc1a715875d..d4edeedaf62 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheSubTitle.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ExperimentalLimitTheNumberOfLinesForTheSubTitle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheTitle.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheTitle.cs index ab23423e91c..01c64811a75 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheTitle.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheTitle.cs @@ -493,6 +493,12 @@ private void CheckValidInstance() public ExperimentalLimitTheNumberOfLinesForTheTitle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs index d7557e3006f..a923516f627 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.cs index 0bbbc59b5c7..1c477109aec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalVisibilityOfTheHeader.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public ExperimentalVisibilityOfTheHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.HeaderTypeNumericSideIndicatorArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.HeaderTypeNumericSideIndicatorArray.cs index 1080a359f3c..74f9dcc973a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.HeaderTypeNumericSideIndicatorArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.HeaderTypeNumericSideIndicatorArray.cs @@ -28,11 +28,13 @@ public readonly partial struct HeaderTypeNumeric public readonly partial struct HeaderTypeNumericSideIndicatorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public HeaderTypeNumericSideIndicatorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.Mutable.cs index 75065dab4b1..06a2ea63787 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.Mutable.cs @@ -1301,6 +1301,64 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DetailsMaxLinesUtf8, out IJsonDocument? _, out int _)) + { + SetDetailsMaxLines(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheDetailsText.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SubTitleMaxLinesUtf8, out IJsonDocument? _, out int _)) + { + SetSubTitleMaxLines(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheSubTitle.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TitleMaxLinesUtf8, out IJsonDocument? _, out int _)) + { + SetTitleMaxLines(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.HeaderTypeNumeric.ExperimentalLimitTheNumberOfLinesForTheTitle.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.MainIndicatorUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.HeaderTypeNumericMainIndicator.Mutable __corvusMainIndicator)) + { + __corvusMainIndicator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.StatusValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Status.Mutable __corvusStatusValue)) + { + __corvusStatusValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.RepresentsTheTypeOfTheHeader.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.RepresentsTheTypeOfTheHeader.cs index f776803907e..d03c1fb9fb2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.RepresentsTheTypeOfTheHeader.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.RepresentsTheTypeOfTheHeader.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheHeader Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.OneOf0Entity.cs index b7eb4ef336f..f3395739537 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.cs index 065728e45ba..37d93d188fb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.TheAlignmentOfTheSideIndicators.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheAlignmentOfTheSideIndicators Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.cs index 48b8ac49539..9915cf43730 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumeric.cs @@ -592,6 +592,12 @@ private void CheckValidInstance() public HeaderTypeNumeric Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.Mutable.cs index 57c26bd0ce3..f672cdd6ee2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.Mutable.cs @@ -469,6 +469,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheStateColorOfTheMainIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheStateColorOfTheMainIndicator.cs index 61045249bf8..f40fe91f24c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheStateColorOfTheMainIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheStateColorOfTheMainIndicator.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheStateColorOfTheMainIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs index 7dd7f52b9cd..64d1703c1c1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.cs index bf3ae4e7090..3305199ccf9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.TheTrendIndicatorDirection.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheTrendIndicatorDirection Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.OneOf0Entity.cs index ae4a10136fb..55568785ed0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.cs index 0a2d9fbdef2..9da7d0cfa1f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.VisibilityOfTheMainIndicator.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public VisibilityOfTheMainIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.cs index f45e0f96c6c..784199f1ff9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericMainIndicator.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public HeaderTypeNumericMainIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.Mutable.cs index 08f68e86200..86244c25eef 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.Mutable.cs @@ -469,6 +469,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.TheStateColorOfTheSideIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.TheStateColorOfTheSideIndicator.cs index cd7a382536b..0016bb2bdf7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.TheStateColorOfTheSideIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.TheStateColorOfTheSideIndicator.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheStateColorOfTheSideIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.OneOf0Entity.cs index 311f9694b1a..eeb475465bd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.cs index f0a54d4c4f5..13c72766685 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.VisibilityOfTheSideIndicator.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public VisibilityOfTheSideIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.cs index bdb0a322903..31911f69c62 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.HeaderTypeNumericSideIndicator.cs @@ -376,6 +376,12 @@ private void CheckValidInstance() public HeaderTypeNumericSideIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.AnyOf0Entity.cs index 19d3637db64..c75feddd602 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.AnyOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.cs index b907fd2eb04..b444fd89c0e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.I18nKeyString.cs @@ -340,6 +340,12 @@ private void CheckValidInstance() public I18nKeyString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.Mutable.cs index af1b43b08ec..bab7f108e83 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.Mutable.cs @@ -225,6 +225,31 @@ public void SetIbnTarget(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.cs index 0c647f7ba40..88bcf186d6f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IbnActionParameters.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public IbnActionParameters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.OneOf0Entity.cs index cfc203ae8a5..f0b511d11ca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.OneOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.cs index 8c30528d3d4..e242996d21d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.ExperimentalTheSizeOfTheIcon.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public ExperimentalTheSizeOfTheIcon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.Mutable.cs index 74afbd12700..f199c34a813 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.Mutable.cs @@ -662,6 +662,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs index 1c343e4ca5b..c9ccfd24ddb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.cs index cccf61aacc0..7ea9b5d026c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.RepresentsTheShapeOfTheIcon.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public RepresentsTheShapeOfTheIcon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.cs index 2d7aa01f576..150e046a1c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Icon.cs @@ -434,6 +434,12 @@ private void CheckValidInstance() public Icon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.OneOf0Entity.cs index e08089a6b39..9a1f674e5a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.OneOf0Entity.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.cs index f80154d0704..d11282f27dd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconBackgroundColor.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public IconBackgroundColor Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.Mutable.cs index fee45dd0d5b..cdee165b5fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.Mutable.cs @@ -596,6 +596,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs index cc0ea860593..5761bbfff6e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.cs index 21b7e3f55ba..2d378734b4e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.RepresentsTheShapeOfTheIcon.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public RepresentsTheShapeOfTheIcon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.VisibilityOfTheIcon.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.VisibilityOfTheIcon.cs index e22af07d6d9..debb5b3e168 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.VisibilityOfTheIcon.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.VisibilityOfTheIcon.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public VisibilityOfTheIcon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.cs index 320e87e6bb7..0ce460051cf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IconWithoutSize.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public IconWithoutSize Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IdDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IdDef.cs index bd203747157..620661e2f1e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IdDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.IdDef.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public IdDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Iddef1.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Iddef1.cs index ccd2dcddf83..7f3abb1e590 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Iddef1.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Iddef1.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public Iddef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.Mutable.cs index 0c4cfacd03e..51740b4f16f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.Mutable.cs @@ -304,6 +304,37 @@ public bool RemoveUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TargetValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Target.Mutable __corvusTargetValue)) + { + __corvusTargetValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.cs index 655b747e97b..87b983fb13a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.Deprecated.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public Deprecated Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.OneOf0Entity.cs index 22834e2b255..b3f9c8bfe62 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.OneOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.cs index 0d1e5c394a6..21a0d1be107 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Identifier.cs @@ -440,6 +440,12 @@ private void CheckValidInstance() public Identifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.ComponentNameEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.ComponentNameEntity.cs index 4d09183ede2..8717691c9d5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.ComponentNameEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.ComponentNameEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ComponentNameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.Mutable.cs index aa9879467a8..20ddcebbbac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.Mutable.cs @@ -461,6 +461,31 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.cs index ab80ee91e88..cf70b210045 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentName.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public RequiredComponentName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.Mutable.cs index ea821a45661..a562352896b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.Mutable.cs @@ -461,6 +461,31 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.cs index f16b30b765a..2eab83924ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.RequiredComponentUsage.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public RequiredComponentUsage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.cs index 991b260275c..6103a97c638 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ImplementingComponentDef.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public ImplementingComponentDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.Mutable.cs index 41432276434..203df13c473 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.Mutable.cs @@ -1022,6 +1022,54 @@ public bool RemoveTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisplayModeUtf8, out IJsonDocument? _, out int _)) + { + SetDisplayMode(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsTheDisplayModeOfTheTile.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeviceTypesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.DeviceType.Mutable __corvusDeviceTypes)) + { + __corvusDeviceTypes.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IndicatorDataSourceUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.Mutable __corvusIndicatorDataSource)) + { + __corvusIndicatorDataSource.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SignatureUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.SignatureDef.Mutable __corvusSignature)) + { + __corvusSignature.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsActionAnTheSemanticObject.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsActionAnTheSemanticObject.cs index 53830f0273e..99bc6dc8560 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsActionAnTheSemanticObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsActionAnTheSemanticObject.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RepresentsActionAnTheSemanticObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.Mutable.cs index 605a4decf59..21b0f33e96a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.Mutable.cs @@ -386,6 +386,31 @@ public bool RemoveRefresh() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.cs index ad37c7322a1..b5be87643af 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsDataSource.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public RepresentsDataSource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsSemanticObject.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsSemanticObject.cs index 24e5e53628b..3c6b950e46f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsSemanticObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsSemanticObject.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RepresentsSemanticObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsTheDisplayModeOfTheTile.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsTheDisplayModeOfTheTile.cs index 88a19d365ad..53981f01f68 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsTheDisplayModeOfTheTile.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.RepresentsTheDisplayModeOfTheTile.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public RepresentsTheDisplayModeOfTheTile Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.cs index bed2b485ca2..b5ae8feee81 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.RequiredActionAndSemanticObject.cs @@ -529,6 +529,12 @@ private void CheckValidInstance() public RequiredActionAndSemanticObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.cs index b77c581dd37..a3da0228f26 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Inbound.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public Inbound Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.Mutable.cs index cc81bcf530d..50c205e5730 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.Mutable.cs @@ -322,6 +322,31 @@ public void SetUrl(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonUriTemplate _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.cs index a0c324a2634..0a5c54c1370 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Infolink.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public Infolink Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateFilterReductionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateFilterReductionEntity.cs index d6ff6123206..f587dd7c231 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateFilterReductionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateFilterReductionEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ActivateFilterReductionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateLrepEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateLrepEntity.cs index 2f5b8a56469..30ffe729c4e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateLrepEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateLrepEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ActivateLrepEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.Mutable.cs index 2cd165be743..7788368febf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.Mutable.cs @@ -403,6 +403,46 @@ public bool RemoveUseHeadRequestForXsrfToken() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ActivateFilterReductionUtf8, out IJsonDocument? _, out int _)) + { + SetActivateFilterReduction(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateFilterReductionEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ActivateLrepUtf8, out IJsonDocument? _, out int _)) + { + SetActivateLrep(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapApfNamespace.ActivateLrepEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseHeadRequestForXsrfTokenUtf8, out IJsonDocument? _, out int _)) + { + SetUseHeadRequestForXsrfToken(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapApfNamespace.UseHeadRequestForXsrfTokenEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.UseHeadRequestForXsrfTokenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.UseHeadRequestForXsrfTokenEntity.cs index e15ab87e2aa..0ec4eea4958 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.UseHeadRequestForXsrfTokenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.UseHeadRequestForXsrfTokenEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public UseHeadRequestForXsrfTokenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.VersionEntity.cs index 18518e1f526..3886b4fb246 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.cs index d0d78ef4340..b633d98c758 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapApfNamespace.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public JsonSchemaForSapApfNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.EmbedsJsonArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.EmbedsJsonArray.cs index 1a7aaadb3f4..2366a965177 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.EmbedsJsonArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.EmbedsJsonArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapAppNamespace public readonly partial struct EmbedsJsonArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public EmbedsJsonArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.OneOf0Entity.cs index 167e3160b42..42d7a0247e2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs index 6c91b1de4cc..215120e3a06 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs @@ -32,11 +32,13 @@ public readonly partial struct RequiredBundleName public readonly partial struct EnhanceWithSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public EnhanceWithSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.Mutable.cs index 60972f9a05d..d87ed25df48 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.Mutable.cs @@ -570,6 +570,31 @@ public bool RemoveTerminologies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs index 24e7f7465fe..6e5c3f61afb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public RepresentsTerminologiesWithAdditionalPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.cs index 6db5a3e6ded..ad06bda31bf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleName.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public RequiredBundleName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.BundleUrlRelativeToEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.BundleUrlRelativeToEntity.cs index bc9282f68e5..4d6be165a19 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.BundleUrlRelativeToEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.BundleUrlRelativeToEntity.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public BundleUrlRelativeToEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs index 6c67a9bb075..40ac59a8d20 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs @@ -32,11 +32,13 @@ public readonly partial struct RequiredBundleUrl public readonly partial struct EnhanceWithSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public EnhanceWithSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.Mutable.cs index 5ffb71194bb..316272ea615 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.Mutable.cs @@ -636,6 +636,36 @@ public bool RemoveTerminologies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleUrlRelativeToUtf8, out IJsonDocument? _, out int _)) + { + SetBundleUrlRelativeTo(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.BundleUrlRelativeToEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs index 5ac98246668..b27241bd2e3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public RepresentsTerminologiesWithAdditionalPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.cs index 3ccca6c799b..3c2cbf3e785 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.RequiredBundleUrl.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public RequiredBundleUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.cs index b7e841a6235..8ff4a006d84 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.cs @@ -489,6 +489,12 @@ private void CheckValidInstance() public I18nEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.JsonStringArray.cs index bb28cf10bd5..ff5e0b2fa00 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapAppNamespace public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.Mutable.cs index 81d51c3449d..fb750c14091 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.Mutable.cs @@ -1971,6 +1971,71 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.I18nUtf8, out IJsonDocument? _, out int _)) + { + SetI18n(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.I18nEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OfflineUtf8, out IJsonDocument? _, out int _)) + { + SetOffline(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OfflineEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ApplicationVersionUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.Mutable __corvusApplicationVersion)) + { + __corvusApplicationVersion.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CrossNavigationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.Mutable __corvusCrossNavigation)) + { + __corvusCrossNavigation.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DestinationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.Mutable __corvusDestination)) + { + __corvusDestination.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SourceTemplateUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.Mutable __corvusSourceTemplate)) + { + __corvusSourceTemplate.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.Mutable __corvusTags)) + { + __corvusTags.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OfflineEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OfflineEntity.cs index cfb9ad38ee5..2936c8a46e9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OfflineEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OfflineEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public OfflineEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OpenSourceArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OpenSourceArray.cs index 66036b868dc..9083f09fcf8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OpenSourceArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.OpenSourceArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapAppNamespace public readonly partial struct OpenSourceArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public OpenSourceArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.Mutable.cs index 2cafd1feec3..4a9177569b7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.Mutable.cs @@ -196,6 +196,31 @@ public void SetName(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.Sou _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.cs index 210a268465c..ebaa63e078c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsASystemAlias.cs @@ -297,6 +297,12 @@ private void CheckValidInstance() public RepresentsASystemAlias Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsApplicationComponentHierarchy.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsApplicationComponentHierarchy.cs index c606b8aef87..be59b5e8f3a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsApplicationComponentHierarchy.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsApplicationComponentHierarchy.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsApplicationComponentHierarchy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.Mutable.cs index 0ff3c4c8b98..1dd23ea072c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.Mutable.cs @@ -397,6 +397,31 @@ public bool RemoveTechnicalAttributes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs index 61aba7fcee2..d71d8fb2593 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TechnicalAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.cs index ea14a2ba42d..252704d4d7d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RepresentsArrayOfKeywords public readonly partial struct TechnicalAttributesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public TechnicalAttributesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.cs index d578e9879c2..7e53a9034e9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RepresentsArrayOfKeywords Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.Mutable.cs index 3120b8df53b..2f9224d02bb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.Mutable.cs @@ -507,6 +507,31 @@ public bool RemoveScopes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.Mutable.cs index 64b02850a4d..dab18e53e47 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.Mutable.cs @@ -270,6 +270,31 @@ public void SetValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.cs index 8e4cfe29671..67e718e2744 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public RepresentsUniqueIdOfTheSite Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.cs index 3bf688ff79d..91c01dfb6be 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public RepresentsScopesOfASite Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.cs index f8ca0ff8632..b1dd98ff1c2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public RepresentsCrossNavigationForInboundAndOutboundTargets Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.Mutable.cs index 02458b7f2ef..fc35da5e65c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.Mutable.cs @@ -266,6 +266,31 @@ public void SetVersion(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.cs index 245907f99bd..70185a04dcf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsMandatoryVersionOfTheApp.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public RepresentsMandatoryVersionOfTheApp Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheNameOfTheProviderWhichOwnsTheApplication.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheNameOfTheProviderWhichOwnsTheApplication.cs index 4a4d13a975c..811004e342d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheNameOfTheProviderWhichOwnsTheApplication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheNameOfTheProviderWhichOwnsTheApplication.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheNameOfTheProviderWhichOwnsTheApplication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.Mutable.cs index ce7fb7e54f1..83d6c163e94 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.Mutable.cs @@ -390,6 +390,31 @@ public void SetVersion(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.cs index e9ea22266b0..a59a51a06f9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsTheTemplateFromWhichTheAppWasGenerated.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public RepresentsTheTemplateFromWhichTheAppWasGenerated Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsUsedDataSourcesWithAUniqueKeyAlias.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsUsedDataSourcesWithAUniqueKeyAlias.cs index c530b35960b..7e340eb5e3c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsUsedDataSourcesWithAUniqueKeyAlias.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsUsedDataSourcesWithAUniqueKeyAlias.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public RepresentsUsedDataSourcesWithAUniqueKeyAlias Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.ResourcesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.ResourcesEntity.cs index ab5eb21e73d..95c973f8e21 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.ResourcesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.ResourcesEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ResourcesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.TypeEntity.cs index d465683f951..fd61ee870a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.TypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.VersionEntity.cs index 4dd121e3e08..c0357198dbb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.cs index 5923a537cca..54aa6f02402 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapAppNamespace.cs @@ -766,6 +766,12 @@ private void CheckValidInstance() public JsonSchemaForSapAppNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.OneOf0Entity.cs index 9a1de59554b..1322e53b8df 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.cs index 8fdadbc2fe2..a1cfe5b68d9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public I18nEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.Mutable.cs index 1c43ff36f2f..900dc3c5f5e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.Mutable.cs @@ -1019,6 +1019,48 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.I18nUtf8, out IJsonDocument? _, out int _)) + { + SetI18n(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ArtifactVersionUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.Mutable __corvusArtifactVersion)) + { + __corvusArtifactVersion.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.Mutable __corvusTags)) + { + __corvusTags.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.Mutable.cs index edb98f8d92e..d6c839632a9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.Mutable.cs @@ -397,6 +397,31 @@ public bool RemoveTechnicalAttributes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs index 61fb0b55fdc..15ccebe9868 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TechnicalAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.cs index 9f9fce050ac..e18fddf02fa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RepresentsArrayOfKeywordsUsedToFindTheArtifact public readonly partial struct TechnicalAttributesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public TechnicalAttributesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.cs index 3bd20708f2b..8843eba01a3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RepresentsArrayOfKeywordsUsedToFindTheArtifact Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.Mutable.cs index d73ddf1eff6..34f7ee1df92 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.Mutable.cs @@ -269,6 +269,31 @@ public void SetVersion(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5Manifest _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.cs index a27fe8f538a..11a1396018c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public RepresentsMandatorySemanticVersionOfTheArtifact Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.TypeEntity.cs index 98da8560369..c0470cf8b5e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.TypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.VersionEntity.cs index 018a983c8e6..e5a4e38e23b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.cs index 09077be5a48..c1ed1557437 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.cs @@ -611,6 +611,12 @@ private void CheckValidInstance() public JsonSchemaForSapArtifactNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.Mutable.cs index 4a5b01513c0..e85ee287417 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.Mutable.cs @@ -561,6 +561,53 @@ public bool RemoveOutputs() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputsUtf8, out IJsonDocument? _, out int _)) + { + SetInputs(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputsUtf8, out IJsonDocument? _, out int _)) + { + SetOutputs(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.InputsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusInputs)) + { + __corvusInputs.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OutputsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusOutputs)) + { + __corvusOutputs.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.Mutable.cs index 31530632ea3..74fc9d42aa5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.Mutable.cs @@ -348,6 +348,31 @@ public bool RemoveLabel() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.RepresentsTheIdOfTheOutcome.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.RepresentsTheIdOfTheOutcome.cs index fc8d171b0da..513c6505968 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.RepresentsTheIdOfTheOutcome.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.RepresentsTheIdOfTheOutcome.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public RepresentsTheIdOfTheOutcome Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.cs index 9999b8be55a..f65d16c904d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.OutcomesEntity.cs @@ -385,6 +385,12 @@ private void CheckValidInstance() public OutcomesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.cs index 26599b08455..b205886b509 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.OutcomesEntityArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapBpaTaskNamespace public readonly partial struct OutcomesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public OutcomesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RepresentsTheCategoryOfTheTaskUi.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RepresentsTheCategoryOfTheTaskUi.cs index a7e2837dacd..4089b74f97c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RepresentsTheCategoryOfTheTaskUi.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RepresentsTheCategoryOfTheTaskUi.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheCategoryOfTheTaskUi Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.Mutable.cs index 61899e8081e..3e2cf264d23 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.Mutable.cs @@ -386,6 +386,31 @@ public void SetOutputs(in Corvus.Text.Json.JsonElement.Source + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.cs index ea4e255c63a..44a31d5e07f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.RequiredInputsAndOutputs.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredInputsAndOutputs Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.VersionEntity.cs index 62eb2548bb2..29fca4827ef 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.cs index fb502baed4f..ca8a183ea17 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public JsonSchemaForSapBpaTaskNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.Mutable.cs index c17e4e4176f..3217bdbf644 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeList.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.Mutable.cs index 5d173bf77a1..ba82b23ba93 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeList.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.cs index 0930e7d1890..b6b6cf3226e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.Mutable.cs index 93fb6da2483..c1fb76ea92b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.TypeEntity.cs index 995f9ad06c4..fe30cf297ae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.cs index 6b0b2900c39..fe27fd35d07 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.WithTypeList.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeList Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.cs index e97749b527e..2526600519c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf0Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.Mutable.cs index 40799292f55..d597401b3d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalytical.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.Mutable.cs index 9395ac9dc68..e85c2e7b764 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalytical.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.cs index 862c8046777..08736511cea 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.Mutable.cs index e60a14dc5df..89dab256b1b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.TypeEntity.cs index 05dde12fd39..99642a0df4f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.cs index 0289eae6ae9..2ff2dd46027 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.WithTypeAnalytical.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeAnalytical Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.cs index 7cd3805c8f3..57d79d38429 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf1Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.Mutable.cs index 6cbedc053f5..faeef4b036a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalyticsCloud.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.Mutable.cs index 003d9d63fbb..b392ba3f297 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeAnalyticsCloud.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.cs index 8cd85b6d185..1f84138c71c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.Mutable.cs index 0cf93550ede..767ad35511d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.TypeEntity.cs index bfadeaca09d..256674d4d41 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.cs index 8817cedce9d..0677dca3e50 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.WithTypeAnalyticsCloud.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeAnalyticsCloud Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.cs index 3ad37eac173..70f4c865b70 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf2Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.Mutable.cs index 330a85640fc..a48eeb0cff2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeTimeline.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.Mutable.cs index bf6c14c5cf6..01d264f8e4d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeTimeline.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.cs index 77ca0d76fcd..8393cb00ce8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.Mutable.cs index 60a3967b846..ef60b845d5c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.TypeEntity.cs index 5b7944cbc6b..81d5cbf9468 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.cs index 6a63d8ab036..2b398cc6e17 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.WithTypeTimeline.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeTimeline Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.cs index f6542d5278d..5675664e114 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf3Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf3Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.Mutable.cs index 7e5f8f5e226..2555ba568dc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeTable.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.Mutable.cs index 0544aa51f19..66735bff61d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeTable.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.cs index 39f5c44f877..8e1acaf0207 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.Mutable.cs index f786181188c..7ae631b88ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.TypeEntity.cs index 3381afac1db..ee859ae9eb3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.cs index ab3d5bd96c2..7958f4221ef 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.WithTypeTable.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeTable Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.cs index 6eda4b440b3..99b93c8652a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf4Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf4Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.Mutable.cs index 376db6e913d..2c8ec8071e9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObject.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.Mutable.cs index 45ba57be579..b03dd24ce8d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeObject.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.cs index 323a61f09a4..241765898fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.Mutable.cs index c0b5d26be25..f347c2a3545 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.TypeEntity.cs index 0fa0efbcc4a..8c402188b05 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.cs index 5778cc51c1c..54c1e8bb8cb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.WithTypeObjectEntity.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeObjectEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.cs index e9439b2dd57..35b0e84f8d5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf5Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf5Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.Mutable.cs index 5f8d55e0658..6146294bad0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeComponent.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.Mutable.cs index 76801b8c9a7..3490e818dd5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeComponent.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.cs index 473446e5a07..6c6cefeffbf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.Mutable.cs index 629bdee1eff..e0e92cd40d6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.TypeEntity.cs index d88135eb0ef..5b0a7e64efb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.cs index 7b7bd23fde0..8f33e8a3b29 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.WithTypeComponent.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.cs index 313fc9ae36b..92e8ca7fb88 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf6Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf6Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.Mutable.cs index 5218d174ae6..25d1075acc8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendar.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.Mutable.cs index a8c15cca74d..20212333656 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeCalendar.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.cs index 02cc56d4107..7fbdb15f3dd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.Mutable.cs index 13861f80c14..f6cf0120c3f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.TypeEntity.cs index e46713518c4..2030db5b65f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.cs index a14a0254480..fe9471f9c1c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.WithTypeCalendar.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeCalendar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.cs index ac6ac610045..9b4bda7d352 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf7Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf7Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.Mutable.cs index 37dcada1f6d..4e06a9921e6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.AdaptiveCard.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.Mutable.cs index 61a4d51d559..ebfd321889f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.AdaptiveCard.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.cs index 507a0c3a109..f91adfb3297 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.Mutable.cs index 1f1df8e7796..6e37b22dd05 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.TypeEntity.cs index 6583f5aca3e..5b1227a7ecf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.cs index 7371071eb4d..36469e1ced5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.WithTypeAdaptiveCard.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeAdaptiveCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.cs index 095c4a2f041..9f7667ee9a7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf8Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf8Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.Mutable.cs index f98bf5f86aa..773bc523da6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeWebPage.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.Mutable.cs index 19577b7f2ba..da328f268cd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.Mutable.cs @@ -318,6 +318,37 @@ public bool RemoveContent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ContentTypeWebPage.Mutable __corvusContent)) + { + __corvusContent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.cs index 7c26a7d1a61..9ceb15f9586 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.ThenEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public ThenEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.Mutable.cs index 74d057cc181..b5338684ad3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.Mutable.cs @@ -277,6 +277,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.TypeEntity.cs index 084bf25b897..227a4a59f67 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.TypeEntity.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.cs index df9ff64a143..484a2ee1e85 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.WithTypeWebPage.cs @@ -359,6 +359,12 @@ private void CheckValidInstance() public WithTypeWebPage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.cs index b1cff82f163..dc83a7e8ea4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.AllOf9Entity.cs @@ -362,6 +362,12 @@ private void CheckValidInstance() public AllOf9Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheCsrfTokensUsedByTheCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheCsrfTokensUsedByTheCard.cs index c841efbd1de..5af0b44931d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheCsrfTokensUsedByTheCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheCsrfTokensUsedByTheCard.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public DescribesTheCsrfTokensUsedByTheCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheMessagesForTheCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheMessagesForTheCard.cs index 3de42a188fe..c0521f673ea 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheMessagesForTheCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesTheMessagesForTheCard.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public DescribesTheMessagesForTheCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesWhatDestinationsAreUsedByTheCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesWhatDestinationsAreUsedByTheCard.cs index 9d3661792f9..58effb065e0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesWhatDestinationsAreUsedByTheCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.DescribesWhatDestinationsAreUsedByTheCard.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public DescribesWhatDestinationsAreUsedByTheCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.Mutable.cs index f65b6dc212b..84e184a562b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.Mutable.cs @@ -245,6 +245,31 @@ public bool RemoveSubmit() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.cs index f2683cd0c36..8f421fa7551 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.cs @@ -296,6 +296,12 @@ private void CheckValidInstance() public HoldsConfigurationForTheDefaultActionHandlers Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.AdditionalPropertiesEntity.cs index af913f6f511..b989a36aa81 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.AdditionalPropertiesEntity.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.cs index e31fe9a9403..a6c283829ae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfFilters.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public MapOfFilters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfParameters.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfParameters.cs index a6cda7afabc..dba43996a81 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfParameters.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.MapOfParameters.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public MapOfParameters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.ModelSizeLimitEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.ModelSizeLimitEntity.cs index 8e1ea250f6c..2ee6b6d87a0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.ModelSizeLimitEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.ModelSizeLimitEntity.cs @@ -495,6 +495,12 @@ private void CheckValidInstance() public ModelSizeLimitEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.Mutable.cs index 7c6e4994c52..84a39d88092 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.Mutable.cs @@ -885,6 +885,42 @@ public bool RemoveParameters() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ModelSizeLimitUtf8, out IJsonDocument? _, out int _)) + { + SetModelSizeLimit(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.ModelSizeLimitEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ActionHandlersUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.HoldsConfigurationForTheDefaultActionHandlers.Mutable __corvusActionHandlers)) + { + __corvusActionHandlers.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.cs index a7524e13ebb..88d15d0f50d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.cs @@ -441,6 +441,12 @@ private void CheckValidInstance() public ConfigurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.Mutable.cs index 043fa38a3ac..115756f0070 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.Mutable.cs @@ -1267,6 +1267,49 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigurationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.Mutable __corvusConfiguration)) + { + __corvusConfiguration.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Data.Mutable __corvusDataValue)) + { + __corvusDataValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FooterUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.Mutable __corvusFooter)) + { + __corvusFooter.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ActionsStripItemArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ActionsStripItemArray.cs index 9b6fe9b8e44..e98656f8647 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ActionsStripItemArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ActionsStripItemArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RepresentCardFooterAttributes public readonly partial struct ActionsStripItemArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ActionsStripItemArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.Mutable.cs index c74c0cc225c..d68d0ef401b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.cs index 801ee21dfe9..215646085e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.cs @@ -489,6 +489,12 @@ private void CheckValidInstance() public RepresentsTheNumberOfTheItemsInOnePage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.cs index 002e334a6ab..326eb877fac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.cs @@ -489,6 +489,12 @@ private void CheckValidInstance() public RepresentsTheTotalCountOfTheItemsInAllPages Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.cs index 4a57360f3ce..f99dfedab60 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public ExperimentalDescribesThePaginator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.OneOf0Entity.cs index d185c067c3e..e8339ead397 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.OneOf0Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.cs index 487f7ce504d..295dacf230f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public ExperimentalVisibilityOfTheFooter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.Mutable.cs index 8ec4c7b3067..534b7680902 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.Mutable.cs @@ -411,6 +411,37 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PaginatorUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.Mutable __corvusPaginator)) + { + __corvusPaginator.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.cs index 764394a4716..4fe0096b043 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public RepresentCardFooterAttributes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.OneOf0Entity.cs index b3ce56b2e15..eaf19f6f26c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.cs index f36f70d0a6d..a8ab980733a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsCardHeaderPositionUnderOrOverTheContent.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public RepresentsCardHeaderPositionUnderOrOverTheContent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsTheTypeOfTheCardSContent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsTheTypeOfTheCardSContent.cs index 03ef4797b2b..585ac346686 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsTheTypeOfTheCardSContent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentsTheTypeOfTheCardSContent.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheCardSContent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.VersionEntity.cs index 5672701dd55..d63ff381bfe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.cs index 5d849ae255e..78a6f8e656c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCardNamespace.cs @@ -709,6 +709,12 @@ private void CheckValidInstance() public JsonSchemaForSapCardNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.Mutable.cs index 7bc7e4d8111..4ead3dd4771 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.Mutable.cs @@ -337,6 +337,36 @@ public bool RemoveService() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PublicUtf8, out IJsonDocument? _, out int _)) + { + SetPublic(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.PublicEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.PublicEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.PublicEntity.cs index 8d7616f5a0b..d6588b459f3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.PublicEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.PublicEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public PublicEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.UniqueBusinessServiceIdentifier.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.UniqueBusinessServiceIdentifier.cs index f96de30f094..c9e2e7e5971 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.UniqueBusinessServiceIdentifier.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.UniqueBusinessServiceIdentifier.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public UniqueBusinessServiceIdentifier Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.VersionEntity.cs index 02982210b66..ae3f69d3a80 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.cs index ff1ad6afe09..fcf5423339a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public JsonSchemaForSapCloudNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.Mutable.cs index fd31ca664e3..accb12323f1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.Mutable.cs @@ -482,6 +482,43 @@ public bool RemoveDigitalAssistant() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContextAnalysisUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.Mutable __corvusContextAnalysis)) + { + __corvusContextAnalysis.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DigitalAssistantUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.Mutable __corvusDigitalAssistant)) + { + __corvusDigitalAssistant.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.cs index d91de2a7095..9ca211e35a5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public AllowAddingObjectsFromAppScreenToCollectionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.JsonStringArray.cs index 0b5d2109685..d8f1a76600b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct SettingsForTheContextAnalysisFeaturesOfSapCoPilot public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.Mutable.cs index 9c059d948d0..96a9ee3cbf7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.Mutable.cs @@ -382,6 +382,36 @@ public bool RemoveWhitelistedEntityTypes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AllowAddingObjectsFromAppScreenToCollectionUtf8, out IJsonDocument? _, out int _)) + { + SetAllowAddingObjectsFromAppScreenToCollection(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.cs index bb450fb3627..4210fb81313 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public SettingsForTheContextAnalysisFeaturesOfSapCoPilot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.JsonStringArray.cs index d2969964a8b..1ac0d27f860 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.JsonStringArray.cs @@ -34,11 +34,13 @@ public readonly partial struct AZaZ09Entity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.Mutable.cs index 943e41939fa..6a586f39766 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.Mutable.cs @@ -452,6 +452,31 @@ public bool RemoveUriValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.cs index b21b97861f5..87fa4a8e028 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.AZaZ09Entity.cs @@ -408,6 +408,12 @@ private void CheckValidInstance() public AZaZ09Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.cs index ebb11a2b908..d38aa6b12b0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.AListOfIntent.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public AListOfIntent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.Mutable.cs index 6002e4d044e..86ec9a91628 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.Mutable.cs @@ -316,6 +316,31 @@ public bool RemoveIntentDefinition() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.cs index d8e42a4e83a..8f9e3f3166c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheDigitalAssistantFeaturesOfSapCoPilot.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public SettingsForTheDigitalAssistantFeaturesOfSapCoPilot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.VersionEntity.cs index cd211346450..a0f8c3e8b69 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.cs index 2617e5b3c91..96ce83c754e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public JsonSchemaForSapCopilotNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.ArcheTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.ArcheTypeEntity.cs index 06a53ef5ca4..081c00bf6f1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.ArcheTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.ArcheTypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public ArcheTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.CloudDevAdaptationStatusEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.CloudDevAdaptationStatusEntity.cs index 25a49b8c326..accf75eef1a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.CloudDevAdaptationStatusEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.CloudDevAdaptationStatusEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public CloudDevAdaptationStatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.JsonStringArray.cs index 21c4242f881..3955d1aee47 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapFioriNamespace public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.Mutable.cs index 780c0e6acba..a4785db576e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.Mutable.cs @@ -481,6 +481,31 @@ public void SetRegistrationIds(in Corvus.Ui5ManifestBenchmark.Current. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.VersionEntity.cs index 2fddb31904c..e4d80b65ee8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.cs index a66fedc910e..51e9a1f4daf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public JsonSchemaForSapFioriNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.Mutable.cs index 6ceaad343ce..a27c02b7540 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.Mutable.cs @@ -530,6 +530,37 @@ public void SetType(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSch _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OriginUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.Mutable __corvusOrigin)) + { + __corvusOrigin.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.Mutable.cs index 515925f6d11..a98af959c54 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.Mutable.cs @@ -273,6 +273,31 @@ public bool RemoveTileId() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.cs index 7960289b0dd..c97761ea8cc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.OriginEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OriginEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsConfigurationParametersOfTheFlpEntry.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsConfigurationParametersOfTheFlpEntry.cs index c0bd7779115..00c40293b3d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsConfigurationParametersOfTheFlpEntry.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsConfigurationParametersOfTheFlpEntry.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public RepresentsConfigurationParametersOfTheFlpEntry Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsSizeOfTheTile.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsSizeOfTheTile.cs index 532c4173b9e..7bccff53978 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsSizeOfTheTile.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.RepresentsSizeOfTheTile.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsSizeOfTheTile Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.TypeEntity.cs index ac087feba97..64cd8da159c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.TypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.VersionEntity.cs index 210502f23f0..c78c5c9dabc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.cs index c859f79dfc2..6538761abe9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public JsonSchemaForSapFlpNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.Mutable.cs index d4989901718..bc4953ddf18 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.Mutable.cs @@ -326,6 +326,31 @@ public void SetTransaction(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5Mani _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsSapScreenPersonasFlavorId.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsSapScreenPersonasFlavorId.cs index 0e99757253a..4001c3d47fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsSapScreenPersonasFlavorId.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsSapScreenPersonasFlavorId.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsSapScreenPersonasFlavorId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsTransactionOfAnApplication.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsTransactionOfAnApplication.cs index 50d6bd130a1..5580e47e309 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsTransactionOfAnApplication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.RepresentsTransactionOfAnApplication.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTransactionOfAnApplication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.VersionEntity.cs index b762c3f99fb..587b8247bbe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.cs index 955a85d3a9f..4648cdf4324 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.cs @@ -337,6 +337,12 @@ private void CheckValidInstance() public JsonSchemaForSapGuiNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.AllowedChartTypesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.AllowedChartTypesEntity.cs index 73f7209b08c..fdf72f954f6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.AllowedChartTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.AllowedChartTypesEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AllowedChartTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.cs index c9f1a5aa4a1..796bdc9743a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.AllowedChartTypesEntityArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapInsightsNamespace public readonly partial struct AllowedChartTypesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public AllowedChartTypesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.FilterEntitySetEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.FilterEntitySetEntity.cs index 17012cac781..c3fd7c0d6c2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.FilterEntitySetEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.FilterEntitySetEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public FilterEntitySetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.Mutable.cs index 46694eea89a..fba8e993fe3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.Mutable.cs @@ -976,6 +976,52 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsDeletedForUserUtf8, out IJsonDocument? _, out int _)) + { + SetIsDeletedForUser(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheDeletedStateForAUser.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsDtCardCopyUtf8, out IJsonDocument? _, out int _)) + { + SetIsDtCardCopy(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheStateOfOriginalOrCopiedCard.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VisibleUtf8, out IJsonDocument? _, out int _)) + { + SetVisible(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheVisibilityTypeOfInsightsCard.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VersionsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.Mutable __corvusVersions)) + { + __corvusVersions.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheDeletedStateForAUser.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheDeletedStateForAUser.cs index 73d93b39f12..9347f73efd2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheDeletedStateForAUser.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheDeletedStateForAUser.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsTheDeletedStateForAUser Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheEnvironmentTypeOfInsightsCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheEnvironmentTypeOfInsightsCard.cs index 0e2eeaa6c35..cab2ff31ff3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheEnvironmentTypeOfInsightsCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheEnvironmentTypeOfInsightsCard.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheEnvironmentTypeOfInsightsCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheStateOfOriginalOrCopiedCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheStateOfOriginalOrCopiedCard.cs index 1f27c497450..8eee652e0c2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheStateOfOriginalOrCopiedCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheStateOfOriginalOrCopiedCard.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsTheStateOfOriginalOrCopiedCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheTemplateNameFromWhereManifestIsGenerated.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheTemplateNameFromWhereManifestIsGenerated.cs index 585970014eb..a3ea8284da4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheTemplateNameFromWhereManifestIsGenerated.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheTemplateNameFromWhereManifestIsGenerated.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheTemplateNameFromWhereManifestIsGenerated Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheVisibilityTypeOfInsightsCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheVisibilityTypeOfInsightsCard.cs index 453ce4366db..c201d52658d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheVisibilityTypeOfInsightsCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsTheVisibilityTypeOfInsightsCard.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsTheVisibilityTypeOfInsightsCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.Mutable.cs index 814d256dffa..f1d062fe9a4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.Mutable.cs @@ -346,6 +346,31 @@ public bool RemoveUi5() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.cs index 84360ceb582..56d5ee38bcd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.RepresentsUi5AndCardGeneratorMiddlewareVersion.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public RepresentsUi5AndCardGeneratorMiddlewareVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.VersionEntity.cs index 79b18f13a2b..e62574dabfd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.VersionEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.cs index e8f5aa60d61..4a1da812ae1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.cs @@ -524,6 +524,12 @@ private void CheckValidInstance() public JsonSchemaForSapInsightsNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.Mutable.cs index e027417d7a5..31037436486 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.Mutable.cs @@ -422,6 +422,31 @@ public void SetUrlTemplateId(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs index 6fb2a3e507c..01dc14498d7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs @@ -326,6 +326,31 @@ public void SetValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.cs index 511ffff9a67..c10165138ba 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.RequiredKeyAndValue.cs @@ -391,6 +391,12 @@ private void CheckValidInstance() public RequiredKeyAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.cs index 7b0b7e30b85..41c95c5d4a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.RequiredKeyAndValueArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapIntegrationNamespace public readonly partial struct RequiredKeyAndValueArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public RequiredKeyAndValueArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.VersionEntity.cs index 43f435e7942..19019940472 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.cs index 1fc1b38222b..742a92aad73 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public JsonSchemaForSapIntegrationNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.Mutable.cs index d69e14ccafb..ff00fae750a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.Mutable.cs @@ -367,6 +367,31 @@ public void SetDefiningRequests(in Corvus.Ui5ManifestBenchmark.Current _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.RepresentsMobileSpecificAttributes.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.RepresentsMobileSpecificAttributes.cs index 3db88e53505..63b1ab12223 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.RepresentsMobileSpecificAttributes.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.RepresentsMobileSpecificAttributes.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public RepresentsMobileSpecificAttributes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.VersionEntity.cs index b650527f365..e9a5de16fe5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.cs index 3f18b4ad29e..c854917122f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public JsonSchemaForSapMobileNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.BHeaderExpandedEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.BHeaderExpandedEntity.cs index 47228a413f2..e3b0b630ec4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.BHeaderExpandedEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.BHeaderExpandedEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public BHeaderExpandedEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.CardsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.CardsEntity.cs index 5713aa33712..849817e6f90 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.CardsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.CardsEntity.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public CardsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ConsiderAnalyticalParametersEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ConsiderAnalyticalParametersEntity.cs index 26617e4acbc..ec693871e98 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ConsiderAnalyticalParametersEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ConsiderAnalyticalParametersEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ConsiderAnalyticalParametersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.DataLoadBehaviourOptionsOnApplicationLaunch.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.DataLoadBehaviourOptionsOnApplicationLaunch.cs index 120c0eab5b3..8c12c0ada0b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.DataLoadBehaviourOptionsOnApplicationLaunch.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.DataLoadBehaviourOptionsOnApplicationLaunch.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public DataLoadBehaviourOptionsOnApplicationLaunch Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.Mutable.cs index 149afad2529..eaab8a2d5f4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.Mutable.cs @@ -280,6 +280,36 @@ public bool RemoveLoadDataOnAppLaunch() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LoadDataOnAppLaunchUtf8, out IJsonDocument? _, out int _)) + { + SetLoadDataOnAppLaunch(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.DataLoadBehaviourOptionsOnApplicationLaunch.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.cs index d3d239f2386..990beffc369 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public DataLoadSettingsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableErrorPageEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableErrorPageEntity.cs index 93ff2600379..fb852bcc9c1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableErrorPageEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableErrorPageEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DisableErrorPageEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableTableCardFlexibilityEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableTableCardFlexibilityEntity.cs index 276a2af77a9..f5a45683c4c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableTableCardFlexibilityEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableTableCardFlexibilityEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public DisableTableCardFlexibilityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLiveFilterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLiveFilterEntity.cs index 333f3753b32..80364eea608 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLiveFilterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLiveFilterEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableLiveFilterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLoadingOfCardsWhenTheyEnterViewport.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLoadingOfCardsWhenTheyEnterViewport.cs index 9a3311e3e22..6082b5c27fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLoadingOfCardsWhenTheyEnterViewport.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLoadingOfCardsWhenTheyEnterViewport.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public EnableLoadingOfCardsWhenTheyEnterViewport Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntitySetEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntitySetEntity.cs index d3940fe3193..f2e2d59b8bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntitySetEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntitySetEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public GlobalFilterEntitySetEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntityTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntityTypeEntity.cs index 7a83c3d5f6d..fc519ff608c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntityTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterEntityTypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public GlobalFilterEntityTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterModelEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterModelEntity.cs index 089b0394920..ce2aecd1f07 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterModelEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.GlobalFilterModelEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public GlobalFilterModelEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.Mutable.cs index 6d4c0278387..80904860435 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.Mutable.cs @@ -1786,6 +1786,115 @@ public bool RemoveUseDateRangeType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BHeaderExpandedUtf8, out IJsonDocument? _, out int _)) + { + SetBHeaderExpanded(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.BHeaderExpandedEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConsiderAnalyticalParametersUtf8, out IJsonDocument? _, out int _)) + { + SetConsiderAnalyticalParameters(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ConsiderAnalyticalParametersEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContainerLayoutUtf8, out IJsonDocument? _, out int _)) + { + SetContainerLayout(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheLayoutOfTheCardContainer.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableErrorPageUtf8, out IJsonDocument? _, out int _)) + { + SetDisableErrorPage(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableErrorPageEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableTableCardFlexibilityUtf8, out IJsonDocument? _, out int _)) + { + SetDisableTableCardFlexibility(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DisableTableCardFlexibilityEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableLazyRenderingUtf8, out IJsonDocument? _, out int _)) + { + SetEnableLazyRendering(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLoadingOfCardsWhenTheyEnterViewport.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnableLiveFilterUtf8, out IJsonDocument? _, out int _)) + { + SetEnableLiveFilter(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.EnableLiveFilterEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RefreshIntervalInMinutesUtf8, out IJsonDocument? _, out int _)) + { + SetRefreshIntervalInMinutes(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.TimeIntervalInMinutesToAutoRefreshTheCardModels.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowBasicSearchUtf8, out IJsonDocument? _, out int _)) + { + SetShowBasicSearch(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowBasicSearchEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowDateInRelativeFormatUtf8, out IJsonDocument? _, out int _)) + { + SetShowDateInRelativeFormat(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowDateInRelativeFormatEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SmartVariantRequiredUtf8, out IJsonDocument? _, out int _)) + { + SetSmartVariantRequired(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.SmartVariantRequiredEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseDateRangeTypeUtf8, out IJsonDocument? _, out int _)) + { + SetUseDateRangeType(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.UseDateRangeTypeEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ChartSettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.Mutable __corvusChartSettings)) + { + __corvusChartSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataLoadSettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.DataLoadSettingsEntity.Mutable __corvusDataLoadSettings)) + { + __corvusDataLoadSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilterSettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.Mutable __corvusFilterSettings)) + { + __corvusFilterSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RefreshStrategyOnAppRestoreUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RefreshStrategiesPropDef.Mutable __corvusRefreshStrategyOnAppRestore)) + { + __corvusRefreshStrategyOnAppRestore.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheLayoutOfTheCardContainer.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheLayoutOfTheCardContainer.cs index 0c99d152fb4..826b9baddb5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheLayoutOfTheCardContainer.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheLayoutOfTheCardContainer.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public RepresentsTheLayoutOfTheCardContainer Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.FlagToEnableDataLabelsOnAnalyticalCharts.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.FlagToEnableDataLabelsOnAnalyticalCharts.cs index ed4c2e426c7..f8d5ef3f131 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.FlagToEnableDataLabelsOnAnalyticalCharts.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.FlagToEnableDataLabelsOnAnalyticalCharts.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public FlagToEnableDataLabelsOnAnalyticalCharts Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.Mutable.cs index 714a97e8c22..6e3bc0d744f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.Mutable.cs @@ -280,6 +280,36 @@ public bool RemoveShowDataLabel() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowDataLabelUtf8, out IJsonDocument? _, out int _)) + { + SetShowDataLabel(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.FlagToEnableDataLabelsOnAnalyticalCharts.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.cs index a7dc463106c..a4cc55a3c9b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public RepresentsTheObjectToStoreAnalyticalChartSettings Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.cs index 2e82e81658f..f6ad735a4be 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public FlagToExcludeValuesFromTheDatePicker Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.Mutable.cs index 71ff7062739..7500beb4b81 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.Mutable.cs @@ -516,6 +516,41 @@ public bool RemoveUseDateRange() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExcludeUtf8, out IJsonDocument? _, out int _)) + { + SetExclude(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UseDateRangeUtf8, out IJsonDocument? _, out int _)) + { + SetUseDateRange(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.cs index ac371fdd5c0..bdfb3117acc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public UseDateRangeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.cs index 9b3cefd9f83..8c867b36b0f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.cs @@ -432,6 +432,12 @@ private void CheckValidInstance() public DateSettingsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.Mutable.cs index 4be474f51b2..1d80f14c4ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.Mutable.cs @@ -316,6 +316,37 @@ public bool RemoveDateSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DateSettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.Mutable __corvusDateSettings)) + { + __corvusDateSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.cs index 995c7be39d0..8de0b23229c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.cs @@ -367,6 +367,12 @@ private void CheckValidInstance() public RepresentsTheObjectToStoreFilterBarConfiguration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ResizableLayoutEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ResizableLayoutEntity.cs index 8ae82825868..c492d302c0b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ResizableLayoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ResizableLayoutEntity.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public ResizableLayoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowBasicSearchEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowBasicSearchEntity.cs index 2004cec24fe..7c09763b4af 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowBasicSearchEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowBasicSearchEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShowBasicSearchEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowDateInRelativeFormatEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowDateInRelativeFormatEntity.cs index e43ee70a06b..9811fc3bda7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowDateInRelativeFormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.ShowDateInRelativeFormatEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShowDateInRelativeFormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.SmartVariantRequiredEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.SmartVariantRequiredEntity.cs index c5df7b3931a..28821f50fff 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.SmartVariantRequiredEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.SmartVariantRequiredEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public SmartVariantRequiredEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.TimeIntervalInMinutesToAutoRefreshTheCardModels.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.TimeIntervalInMinutesToAutoRefreshTheCardModels.cs index 8d522722130..2cce5a2de3d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.TimeIntervalInMinutesToAutoRefreshTheCardModels.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.TimeIntervalInMinutesToAutoRefreshTheCardModels.cs @@ -412,6 +412,12 @@ private void CheckValidInstance() public TimeIntervalInMinutesToAutoRefreshTheCardModels Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.UseDateRangeTypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.UseDateRangeTypeEntity.cs index d3b4c37bd1d..b2d151c1956 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.UseDateRangeTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.UseDateRangeTypeEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public UseDateRangeTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.VersionEntity.cs index 36d752cfbcd..7099b7b75c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.cs index c4475d535ee..d752af0950b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.cs @@ -728,6 +728,12 @@ private void CheckValidInstance() public JsonSchemaForSapOvpNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace_._resentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace_._resentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.cs index bd29d02e707..5a1839eb3bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace_._resentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapOvpNamespace_._resentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.cs @@ -448,6 +448,12 @@ private void CheckValidInstance() public RepresentsTheFilterFieldDefinitionForEachField Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.ContentitemArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.ContentitemArray.cs index 8fc4c4e152c..8e2cb6ffc8f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.ContentitemArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.ContentitemArray.cs @@ -23,11 +23,13 @@ public readonly partial struct JsonSchemaForSapPackageNamespace public readonly partial struct ContentitemArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ContentitemArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.OneOf0Entity.cs index 0c0d108db94..1ffdf2eb7ed 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.cs index 92a1a64b20e..69fa7a5818f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.cs @@ -355,6 +355,12 @@ private void CheckValidInstance() public I18nEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.JsonStringArray.cs index a52c8049b24..a4fa5cbbacb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapPackageNamespace public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.Mutable.cs index a969da2b68a..b3973ba6b0b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.Mutable.cs @@ -1725,6 +1725,78 @@ public void SetVendorValue(in Corvus.Ui5ManifestBenchmark.Current.Ui5M _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.I18nUtf8, out IJsonDocument? _, out int _)) + { + SetI18n(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.I18nEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DependenciesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.Mutable __corvusDependencies)) + { + __corvusDependencies.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DocumentationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Infolink.Mutable __corvusDocumentation)) + { + __corvusDocumentation.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HomepageUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Infolink.Mutable __corvusHomepage)) + { + __corvusHomepage.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PackageVersionUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.Mutable __corvusPackageVersion)) + { + __corvusPackageVersion.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SupportUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Infolink.Mutable __corvusSupport)) + { + __corvusSupport.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TagsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.Mutable __corvusTags)) + { + __corvusTags.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VendorValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Vendor.Mutable __corvusVendorValue)) + { + __corvusVendorValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.Mutable.cs index 9a1dfe8d2cb..80fc0e622fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.Mutable.cs @@ -397,6 +397,31 @@ public bool RemoveTechnicalAttributes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs index 116acbdbdf5..990015540eb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public TechnicalAttributesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.cs index 35cbb54169f..ea2837a37f4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.cs @@ -25,11 +25,13 @@ public readonly partial struct RepresentsArrayOfKeywordsUsedToFindThePackage public readonly partial struct TechnicalAttributesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public TechnicalAttributesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.cs index f8ed40c202b..dcd45707bb3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RepresentsArrayOfKeywordsUsedToFindThePackage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.JsonStringArray.cs index 758797d7e6b..3f683352638 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.JsonStringArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RepresentsTheProductsAndServiceThatThePacakgeDepe public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.ListOfServArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.ListOfServArray.cs index aab83737869..882eeb6adb4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.ListOfServArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.ListOfServArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RepresentsTheProductsAndServiceThatThePacakgeDepe public readonly partial struct ListOfServArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public ListOfServArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.Mutable.cs index 72ec09247cd..7185cca0c73 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.Mutable.cs @@ -418,6 +418,31 @@ public bool RemoveServices() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.cs index ad3a06de819..fd56bfbbf40 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsTheProductsAndServiceThatThePacakgeDependsOn.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public RepresentsTheProductsAndServiceThatThePacakgeDependsOn Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.Mutable.cs index f35b62e37a0..d40b5e7e7a2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.Mutable.cs @@ -338,6 +338,36 @@ public void SetVersion(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5Manifest _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UpgradeNotificationUtf8, out IJsonDocument? _, out int _)) + { + SetUpgradeNotification(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.UpgradeNotificationEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.UpgradeNotificationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.UpgradeNotificationEntity.cs index ab9d0d26524..d1d6f6d2a2e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.UpgradeNotificationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.UpgradeNotificationEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public UpgradeNotificationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.cs index 6737164197d..30c6d6babbf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RequiredVersion.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public RequiredVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.TypeEntity.cs index b690e377f6d..a19317f0a69 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.TypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.VersionEntity.cs index 9d287bb35ac..a921c6b2adf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.cs index 3d20661dcbe..39f6e090885 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.cs @@ -768,6 +768,12 @@ private void CheckValidInstance() public JsonSchemaForSapPackageNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.Mutable.cs index 6c38f3c8f9d..aca96a7d1ce 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveUriNwbc() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.VersionEntity.cs index c991f6dcf28..e1e61190f7c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.cs index 7bab8a7f4db..59a24b19055 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public JsonSchemaForSapPlatformAbapNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.JsonStringArray.cs index 3e1e407c3e5..49690019bb3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapPlatformCfNamespace public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.Mutable.cs index 565c9f74f68..cdad774e146 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.Mutable.cs @@ -380,6 +380,31 @@ public bool RemoveOAuthScopes() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.VersionEntity.cs index 34f928013c0..59add607d7c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.cs index d810885ebb7..784b13a579e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public JsonSchemaForSapPlatformCfNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.Mutable.cs index 4672b6bf4d1..6c77bc06681 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.Mutable.cs @@ -601,6 +601,31 @@ public bool RemoveUriNwbc() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.RepresentsTheHtml5ApplicationName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.RepresentsTheHtml5ApplicationName.cs index fb1628e444c..07190a7a3be 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.RepresentsTheHtml5ApplicationName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.RepresentsTheHtml5ApplicationName.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheHtml5ApplicationName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.VersionEntity.cs index 990b0e05721..eb404a57d4b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.cs index 01b7485bb25..0e489e37eb1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public JsonSchemaForSapPlatformHcpNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.Mutable.cs index 25d05c03fdc..429fea964fd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.Mutable.cs @@ -344,6 +344,31 @@ public bool RemoveCompatible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.VersionEntity.cs index 4012d8618ef..13da130a348 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.cs index 25e5fdda7e6..c6f346e4462 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public JsonSchemaForSapPlatformMobilecardsNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.Mutable.cs index f481f3d3ea6..31081b92164 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.Mutable.cs @@ -392,6 +392,31 @@ public bool RemoveUriValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.VersionEntity.cs index 40aa40fb7eb..12e06ca7bfc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.cs index 6e82d08ee8c..0899d8c5682 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public JsonSchemaForSapPlatformSfsfNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.Mutable.cs index d57124c6b12..133df590d0f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.Mutable.cs @@ -486,6 +486,37 @@ public bool RemoveRoutingValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoutingValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.Mutable __corvusRoutingValue)) + { + __corvusRoutingValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs index b3a3096d9ca..bbb253bf064 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs @@ -312,6 +312,12 @@ private void CheckValidInstance() public RepresentsAnIndicatorWhetherAnAppIsFlexEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.cs index 049ad00f441..0e4b7674e01 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.OneOf1Entity.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.Mutable.cs index 2bc34f3f944..44889a50624 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.Mutable.cs @@ -475,6 +475,43 @@ public bool RemoveRouting() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RootViewUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RootViewDefFlexEnabled.Mutable __corvusRootView)) + { + __corvusRootView.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoutingUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingFlexEnabled.Mutable __corvusRouting)) + { + __corvusRouting.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs index 9f3e8c62cfd..3c0823c31e1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.RepresentsAnIndicatorWhetherAnAppIsFlexEnabled.cs @@ -312,6 +312,12 @@ private void CheckValidInstance() public RepresentsAnIndicatorWhetherAnAppIsFlexEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.cs index 68202591361..f39ba98cdfd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.RequiredFlexEnabled.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public RequiredFlexEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.cs index f9a49ff0080..ee6ee9910bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.Mutable.cs index a3afa066ed8..58b375dbff6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.Mutable.cs @@ -1944,6 +1944,76 @@ public bool RemoveServices() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FlexExtensionPointEnabledUtf8, out IJsonDocument? _, out int _)) + { + SetFlexExtensionPointEnabled(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.FlexExtensionPointEnabledEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HandleValidationUtf8, out IJsonDocument? _, out int _)) + { + SetHandleValidation(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.HandleValidationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsCloudDevAdaptationUtf8, out IJsonDocument? _, out int _)) + { + SetIsCloudDevAdaptation(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.IsCloudDevAdaptationEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentDensitiesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.Mutable __corvusContentDensities)) + { + __corvusContentDensities.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DependenciesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.Mutable __corvusDependencies)) + { + __corvusDependencies.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtendsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.Mutable __corvusExtends)) + { + __corvusExtends.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibraryUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.Mutable __corvusLibrary)) + { + __corvusLibrary.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Resource.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensi_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensi_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.Mutable.cs index 46cd6d8f4ef..6938dd5c0cd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensi_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensi_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.Mutable.cs @@ -310,6 +310,31 @@ public void SetVersion(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndD_._I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndD_._I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs index e3e69def9c6..30a5d9cf00e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndD_._I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndD_._I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public RepresentsTerminologiesWithAdditionalPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDe_._I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDe_._I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs index ef527efe4b6..53e18fa1a11 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDe_._I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDe_._I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public RepresentsTerminologiesWithAdditionalPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ComponentUsagesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ComponentUsagesEntity.cs index 98d02bf2411..75313b4ffd3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ComponentUsagesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ComponentUsagesEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public ComponentUsagesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.FlexExtensionPointEnabledEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.FlexExtensionPointEnabledEntity.cs index 9d403f65ce1..c4b783c5270 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.FlexExtensionPointEnabledEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.FlexExtensionPointEnabledEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public FlexExtensionPointEnabledEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.HandleValidationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.HandleValidationEntity.cs index 457cb9acbb5..d6f61658aae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.HandleValidationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.HandleValidationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public HandleValidationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.IsCloudDevAdaptationEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.IsCloudDevAdaptationEntity.cs index 5868823d0b1..f93dc6829f9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.IsCloudDevAdaptationEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.IsCloudDevAdaptationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public IsCloudDevAdaptationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ModelsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ModelsEntity.cs index f0e1b63580f..a0395ce72b1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ModelsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ModelsEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public ModelsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Mutable.cs index 77b6f8dcfc1..72af78e0aa5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Mutable.cs @@ -1874,6 +1874,76 @@ public bool RemoveServices() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FlexExtensionPointEnabledUtf8, out IJsonDocument? _, out int _)) + { + SetFlexExtensionPointEnabled(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.FlexExtensionPointEnabledEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HandleValidationUtf8, out IJsonDocument? _, out int _)) + { + SetHandleValidation(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.HandleValidationEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsCloudDevAdaptationUtf8, out IJsonDocument? _, out int _)) + { + SetIsCloudDevAdaptation(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.IsCloudDevAdaptationEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContentDensitiesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.Mutable __corvusContentDensities)) + { + __corvusContentDensities.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DependenciesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.Mutable __corvusDependencies)) + { + __corvusDependencies.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ExtendsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.Mutable __corvusExtends)) + { + __corvusExtends.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LibraryUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.Mutable __corvusLibrary)) + { + __corvusLibrary.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ResourcesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Resource.Mutable __corvusResources)) + { + __corvusResources.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfTheServices.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfTheServices.cs index 39bdaa38ac5..846b80aba54 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfTheServices.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfTheServices.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public RepresentsAListOfTheServices Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfUi5ShortcutCommands.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfUi5ShortcutCommands.cs index d9adba42737..922b0116030 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfUi5ShortcutCommands.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfUi5ShortcutCommands.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public RepresentsAListOfUi5ShortcutCommands Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsANameOfTheUi5Component.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsANameOfTheUi5Component.cs index 952c3f05e08..9408591fbd1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsANameOfTheUi5Component.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsANameOfTheUi5Component.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RepresentsANameOfTheUi5Component Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.Mutable.cs index 8891da20333..9c2fbcea77c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.Mutable.cs @@ -377,6 +377,31 @@ public bool RemoveMinVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.cs index 01158036e32..074289885e6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheExtensionOfAnAdditionalComponent.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public RepresentsTheExtensionOfAnAdditionalComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheStaticConfigurationForComponents.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheStaticConfigurationForComponents.cs index ac88790b2db..207d773f11f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheStaticConfigurationForComponents.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheStaticConfigurationForComponents.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public RepresentsTheStaticConfigurationForComponents Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.cs index 1235d61caf1..ec9e57f4585 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public RequiredBundleName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.cs index 5b028390817..e78e81ee906 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.cs @@ -382,6 +382,12 @@ private void CheckValidInstance() public RequiredBundleUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.cs index 9099ea583af..cf5fd8063f2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.cs @@ -500,6 +500,12 @@ private void CheckValidInstance() public I18nEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.Mutable.cs index 1415255f95f..d40bc5993f3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.Mutable.cs @@ -413,6 +413,31 @@ public bool RemoveI18n() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.cs index af7d9cd646b..59e10ac7b11 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.cs @@ -338,6 +338,12 @@ private void CheckValidInstance() public RepresentsUi5LibrarySpecificProperties Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.cs index c9eb882e5fa..45e5938f03d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredContentDensitiesAndDependencies public readonly partial struct RequiredAppVariantIdAndLayerAndVersionArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RequiredAppVariantIdAndLayerAndVersionArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.Mutable.cs index a63d7d4f228..427c59a93e3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.Mutable.cs @@ -253,6 +253,31 @@ public void SetCozy(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonBoolean.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.cs index b0f889c70d1..6dbf8e9bad4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredCompactAndCozy.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public RequiredCompactAndCozy Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.ComponentsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.ComponentsEntity.cs index e4747060518..63a317a00e2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.ComponentsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.ComponentsEntity.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public ComponentsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.LibsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.LibsEntity.cs index 2a41826b17c..00b6b56112e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.LibsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.LibsEntity.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public LibsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.Mutable.cs index 752c81dae34..eac5f2bad54 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.Mutable.cs @@ -402,6 +402,31 @@ public void SetMinUi5Version(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonS _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.cs index 8c30e7a5d3c..fca7f26bb78 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredMinUi5Version.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public RequiredMinUi5Version Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ResourceRootsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ResourceRootsEntity.cs index a4dc34b1b41..816f674cc34 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ResourceRootsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ResourceRootsEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public ResourceRootsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.VersionEntity.cs index ccf83d1d381..10e281c68e2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.VersionEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.cs index ebdcf568f3e..97c940c4c41 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.cs @@ -746,6 +746,12 @@ private void CheckValidInstance() public RequiredContentDensitiesAndDependencies Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._SpecificProperties.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._SpecificProperties.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs index ec87e080e4a..220e1d942cb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._SpecificProperties.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._SpecificProperties.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs @@ -36,11 +36,13 @@ public readonly partial struct RequiredBundleUrl public readonly partial struct EnhanceWithSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public EnhanceWithSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._esentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._esentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.Mutable.cs index 081a52b8923..7eff94e256b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._esentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._esentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.Mutable.cs @@ -574,6 +574,31 @@ public bool RemoveTerminologies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._pecificProperties.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._pecificProperties.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs index 56feac9986c..2ca571d4df7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._pecificProperties.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._pecificProperties.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs @@ -36,11 +36,13 @@ public readonly partial struct RequiredBundleName public readonly partial struct EnhanceWithSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public EnhanceWithSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._sentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._sentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.Mutable.cs index 3507c8c2355..291b7d36b68 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._sentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._sentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.Mutable.cs @@ -574,6 +574,31 @@ public bool RemoveTerminologies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.cs index 520b8740187..2212f4db8a0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.cs @@ -821,6 +821,12 @@ private void CheckValidInstance() public JsonSchemaForSapUi5Namespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace_._tentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace_._tentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.cs index 3e712655102..e786e8c2a50 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace_._tentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUi5Namespace_._tentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public RequiredAppVariantIdAndLayerAndVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.Mutable.cs index c25df479fc4..b89c3f7e747 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.Mutable.cs @@ -407,6 +407,31 @@ public bool RemoveSettings() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.OneOf1Entity.cs index 8531ee20409..33c25fb31ff 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.OneOf1Entity.cs @@ -396,6 +396,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.PagesArrayArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.PagesArrayArray.cs index 8da2259603c..ead727b30c5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.PagesArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.PagesArrayArray.cs @@ -25,11 +25,13 @@ public readonly partial struct PagesEntity public readonly partial struct PagesArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public PagesArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.cs index f9dd628ead1..05af4789ac3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public PagesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.VersionEntity.cs index 401b18ab3a7..32e9221a5e0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.VersionEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.cs index c6d2a340ff2..8b241518b2b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public JsonSchemaForSapUiGenericAppNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.Mutable.cs index 7a6a71d2e73..9f17c780010 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.Mutable.cs @@ -508,6 +508,31 @@ public void SetTablet(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.Mutable.cs index c2150c028bc..dcaa111e80b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.Mutable.cs @@ -474,6 +474,31 @@ public void SetTablet(in Corvus.Text.Json.JsonElement.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.cs index beff071569d..c523c2dd600 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.RequiredDesktopAndPhoneAndTablet.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public RequiredDesktopAndPhoneAndTablet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.cs index 28a5e98d0dd..02e42a58ce8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.cs @@ -445,6 +445,12 @@ private void CheckValidInstance() public DeviceTypesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.JsonStringArray.cs index 7c2abae5624..c61730ec990 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct JsonSchemaForSapUiNamespace public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.Mutable.cs index f310b513776..0e46e4df577 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.Mutable.cs @@ -692,6 +692,48 @@ public void SetTechnology(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5Manif _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TechnologyUtf8, out IJsonDocument? _, out int _)) + { + SetTechnology(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUiNamespace.TechnologyEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DeviceTypesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUiNamespace.DeviceTypesEntity.Mutable __corvusDeviceTypes)) + { + __corvusDeviceTypes.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IconsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.Mutable __corvusIcons)) + { + __corvusIcons.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.Mutable.cs index 7cfd3147d21..4de59a0854c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.Mutable.cs @@ -537,6 +537,31 @@ public bool RemoveTablet2() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.cs index 46b9817041e..0abdd2e2f66 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.RepresentsIconsWhichUsedInApplication.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public RepresentsIconsWhichUsedInApplication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.TechnologyEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.TechnologyEntity.cs index b70115c2ef1..cd83a557ce5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.TechnologyEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.TechnologyEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TechnologyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.VersionEntity.cs index 169cdb92d49..fa53f5ed426 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.cs index cdf9853add0..22ef20a33ea 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUiNamespace.cs @@ -476,6 +476,12 @@ private void CheckValidInstance() public JsonSchemaForSapUiNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.Mutable.cs index 6da31ef1978..4d7993cd1c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.Mutable.cs @@ -260,6 +260,31 @@ public void SetUriValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.VersionEntity.cs index 7f2443fde74..9d84fd43c9c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.cs index 448928f17be..44fe5e6a7f9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public JsonSchemaForSapUrlNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.Mutable.cs index 9362a23d1af..a3a73f76655 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.Mutable.cs @@ -260,6 +260,31 @@ public void SetWcfTargetId(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5Mani _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.RepresentsTheTargetTechnicalIdForAWcfApplication.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.RepresentsTheTargetTechnicalIdForAWcfApplication.cs index 05fff9aa508..5f237521be9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.RepresentsTheTargetTechnicalIdForAWcfApplication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.RepresentsTheTargetTechnicalIdForAWcfApplication.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheTargetTechnicalIdForAWcfApplication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.VersionEntity.cs index 3bb45a595bf..133bb804aa8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.cs index a412ae66b87..8501ab6482b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public JsonSchemaForSapWcfNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.CompatibilityModeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.CompatibilityModeEntity.cs index d0a9aaee70f..38e52b9f36a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.CompatibilityModeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.CompatibilityModeEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public CompatibilityModeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.Mutable.cs index dcebf6c3358..1d5949d913f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.Mutable.cs @@ -458,6 +458,36 @@ public bool RemoveFlavorId() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CompatibilityModeUtf8, out IJsonDocument? _, out int _)) + { + SetCompatibilityMode(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.CompatibilityModeEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplication.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplication.cs index 73ababe986d..e9c7f4ba917 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplication.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplication.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsIdOfAnApplication Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplicationConfiguration.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplicationConfiguration.cs index b4c6b12c064..a2828620810 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplicationConfiguration.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsIdOfAnApplicationConfiguration.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsIdOfAnApplicationConfiguration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsSapScreenPersonasFlavorId.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsSapScreenPersonasFlavorId.cs index 51bde3c7473..da781505885 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsSapScreenPersonasFlavorId.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.RepresentsSapScreenPersonasFlavorId.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsSapScreenPersonasFlavorId Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.VersionEntity.cs index e4366394773..1d694a4a618 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.VersionEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.cs index e8e293d8fab..4bbfc8bc43e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public JsonSchemaForSapWdaNamespace Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.Mutable.cs index a87a5248967..4bd114328d8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.Mutable.cs @@ -344,6 +344,36 @@ public bool RemoveMinVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LazyUtf8, out IJsonDocument? _, out int _)) + { + SetLazy(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Lib.RepresentsIndicatorToLazyLoadingLib.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.RepresentsIndicatorToLazyLoadingLib.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.RepresentsIndicatorToLazyLoadingLib.cs index 12d0efb37df..d9efa6aa1aa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.RepresentsIndicatorToLazyLoadingLib.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.RepresentsIndicatorToLazyLoadingLib.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsIndicatorToLazyLoadingLib Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.cs index a30912bde67..ccbbfacf716 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Lib.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public Lib Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Microchart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Microchart.cs index 374a0ad4f0b..ff462b8242a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Microchart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Microchart.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public Microchart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.MicrochartBulletThresholdArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.MicrochartBulletThresholdArray.cs index afa55ccd10d..90a7e0f04c0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.MicrochartBulletThresholdArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.MicrochartBulletThresholdArray.cs @@ -28,11 +28,13 @@ public readonly partial struct MicrochartBullet public readonly partial struct MicrochartBulletThresholdArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public MicrochartBulletThresholdArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.Mutable.cs index 56c293ce38b..67a0ba9c2e4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.Mutable.cs @@ -824,6 +824,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.RepresentsTheTypeOfTheMicrochart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.RepresentsTheTypeOfTheMicrochart.cs index 0aa6834747b..2aa146711b5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.RepresentsTheTypeOfTheMicrochart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.RepresentsTheTypeOfTheMicrochart.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheMicrochart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheActualValueShownAsAColoredHorizontalBar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheActualValueShownAsAColoredHorizontalBar.cs index e8181dd46c3..0d4a2730942 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheActualValueShownAsAColoredHorizontalBar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheActualValueShownAsAColoredHorizontalBar.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public TheActualValueShownAsAColoredHorizontalBar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMaximumScaleValueForTheBarChart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMaximumScaleValueForTheBarChart.cs index bc7f51c7200..39679cc9073 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMaximumScaleValueForTheBarChart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMaximumScaleValueForTheBarChart.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public TheMaximumScaleValueForTheBarChart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMinimumScaleValueForTheBarChart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMinimumScaleValueForTheBarChart.cs index 7cdecaf6c31..eeab597182a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMinimumScaleValueForTheBarChart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheMinimumScaleValueForTheBarChart.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public TheMinimumScaleValueForTheBarChart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheStateColorOfTheBar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheStateColorOfTheBar.cs index 5081d47dc56..b364f8b6af6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheStateColorOfTheBar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheStateColorOfTheBar.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheStateColorOfTheBar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheTargetValueDisplayedAsAVerticalLineMarker.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheTargetValueDisplayedAsAVerticalLineMarker.cs index f874af07420..4ac56e9b4b4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheTargetValueDisplayedAsAVerticalLineMarker.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.TheTargetValueDisplayedAsAVerticalLineMarker.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public TheTargetValueDisplayedAsAVerticalLineMarker Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.cs index d13c2c3396d..3ff46059667 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBullet.cs @@ -479,6 +479,12 @@ private void CheckValidInstance() public MicrochartBullet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.Mutable.cs index 66358ffffaf..26b476f9e2b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.Mutable.cs @@ -271,6 +271,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheStateColorOfTheThreshold.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheStateColorOfTheThreshold.cs index d9a670b11bf..d87e20de125 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheStateColorOfTheThreshold.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheStateColorOfTheThreshold.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheStateColorOfTheThreshold Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheValueOfTheThreshold.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheValueOfTheThreshold.cs index 7a758389b22..32f711568a6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheValueOfTheThreshold.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.TheValueOfTheThreshold.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public TheValueOfTheThreshold Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.cs index ea3ab0781b3..ce9dc063c16 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartBulletThreshold.cs @@ -308,6 +308,12 @@ private void CheckValidInstance() public MicrochartBulletThreshold Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.MicrochartStackedBarBarArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.MicrochartStackedBarBarArray.cs index 5f6a97af073..f31318ae45c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.MicrochartStackedBarBarArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.MicrochartStackedBarBarArray.cs @@ -28,11 +28,13 @@ public readonly partial struct MicrochartStackedBar public readonly partial struct MicrochartStackedBarBarArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public MicrochartStackedBarBarArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.Mutable.cs index 30f1c538609..465f0eae6ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.Mutable.cs @@ -494,6 +494,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.RepresentsTheTypeOfTheMicrochart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.RepresentsTheTypeOfTheMicrochart.cs index ff0467dc32e..7514e7c5e33 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.RepresentsTheTypeOfTheMicrochart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.RepresentsTheTypeOfTheMicrochart.cs @@ -325,6 +325,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheMicrochart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.TheMaximumScaleValueForTheBarChart.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.TheMaximumScaleValueForTheBarChart.cs index 377e4302bb6..4dde6ed2465 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.TheMaximumScaleValueForTheBarChart.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.TheMaximumScaleValueForTheBarChart.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public TheMaximumScaleValueForTheBarChart Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.cs index 486677d96eb..62d226e8a85 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBar.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public MicrochartStackedBar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.Mutable.cs index 97631e558db..78803adf017 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.Mutable.cs @@ -403,6 +403,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheActualValueShownAsAColoredHorizontalBar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheActualValueShownAsAColoredHorizontalBar.cs index 92df502d1a7..825b2a45e0e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheActualValueShownAsAColoredHorizontalBar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheActualValueShownAsAColoredHorizontalBar.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public TheActualValueShownAsAColoredHorizontalBar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheColorOfTheBar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheColorOfTheBar.cs index f81839d57e6..d2122b911d9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheColorOfTheBar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.TheColorOfTheBar.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheColorOfTheBar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.cs index ecbf4cb9866..6c7764835c4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.MicrochartStackedBarBar.cs @@ -350,6 +350,12 @@ private void CheckValidInstance() public MicrochartStackedBarBar Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.Mutable.cs index 9d0ab3e9f5b..7fdd40202de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.Mutable.cs @@ -500,6 +500,42 @@ public bool RemoveUriValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PreloadUtf8, out IJsonDocument? _, out int _)) + { + SetPreload(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Model.PreloadEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SettingsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Ui5setting.Mutable __corvusSettings)) + { + __corvusSettings.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.PreloadEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.PreloadEntity.cs index 82f9ca0447b..81857788952 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.PreloadEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.PreloadEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public PreloadEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.cs index b34bac29985..f1cb128351b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Model.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public Model Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Mutable.cs index b0e639e1028..22abb267fef 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Mutable.cs @@ -3387,6 +3387,187 @@ public bool RemoveStartUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapApfUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapApfNamespace.Mutable __corvusSapApf)) + { + __corvusSapApf.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapAppUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapAppNamespace.Mutable __corvusSapApp)) + { + __corvusSapApp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapArtifactUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.Mutable __corvusSapArtifact)) + { + __corvusSapArtifact.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapBpaTaskUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapBpaTaskNamespace.Mutable __corvusSapBpaTask)) + { + __corvusSapBpaTask.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapCardUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCardNamespace.Mutable __corvusSapCard)) + { + __corvusSapCard.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapCloudUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.Mutable __corvusSapCloud)) + { + __corvusSapCloud.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapCopilotUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.Mutable __corvusSapCopilot)) + { + __corvusSapCopilot.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapFioriUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.Mutable __corvusSapFiori)) + { + __corvusSapFiori.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapFlpUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapFlpNamespace.Mutable __corvusSapFlp)) + { + __corvusSapFlp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapGuiUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapGuiNamespace.Mutable __corvusSapGui)) + { + __corvusSapGui.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapInsightsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapInsightsNamespace.Mutable __corvusSapInsights)) + { + __corvusSapInsights.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapIntegrationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapIntegrationNamespace.Mutable __corvusSapIntegration)) + { + __corvusSapIntegration.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapMobileUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapMobileNamespace.Mutable __corvusSapMobile)) + { + __corvusSapMobile.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapOvpUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.Mutable __corvusSapOvp)) + { + __corvusSapOvp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapPackageUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.Mutable __corvusSapPackage)) + { + __corvusSapPackage.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapPlatformAbapUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPlatformAbapNamespace.Mutable __corvusSapPlatformAbap)) + { + __corvusSapPlatformAbap.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapPlatformCfUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPlatformCfNamespace.Mutable __corvusSapPlatformCf)) + { + __corvusSapPlatformCf.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapPlatformHcpUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPlatformHcpNamespace.Mutable __corvusSapPlatformHcp)) + { + __corvusSapPlatformHcp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapPlatformMobilecardsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPlatformMobilecardsNamespace.Mutable __corvusSapPlatformMobilecards)) + { + __corvusSapPlatformMobilecards.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapPlatformSfsfUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapPlatformSfsfNamespace.Mutable __corvusSapPlatformSfsf)) + { + __corvusSapPlatformSfsf.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapUiUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUiNamespace.Mutable __corvusSapUi)) + { + __corvusSapUi.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapUiGenericAppUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.Mutable __corvusSapUiGenericApp)) + { + __corvusSapUiGenericApp.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapUi5Utf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.Mutable __corvusSapUi5)) + { + __corvusSapUi5.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapUrlUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapUrlNamespace.Mutable __corvusSapUrl)) + { + __corvusSapUrl.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapWcfUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapWcfNamespace.Mutable __corvusSapWcf)) + { + __corvusSapWcf.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.SapWdaUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.JsonSchemaForSapWdaNamespace.Mutable __corvusSapWda)) + { + __corvusSapWda.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.Mutable.cs index 0c5222468a9..83c4f61c5fe 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.Mutable.cs @@ -445,6 +445,49 @@ public bool RemoveEdit() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CreateValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ActionPropDef.Mutable __corvusCreateValue)) + { + __corvusCreateValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisplayUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ActionPropDef.Mutable __corvusDisplay)) + { + __corvusDisplay.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EditUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ActionPropDef.Mutable __corvusEdit)) + { + __corvusEdit.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.cs index 37292d3bc23..14c6e6c9cd6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.NavigationDef.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public NavigationDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectName.cs index 0be97ea2c84..4136f34a79d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectName.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ObjectName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.CustomActionsSettingArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.CustomActionsSettingArray.cs index 46972aeb142..76bc9bdfce7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.CustomActionsSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.CustomActionsSettingArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ObjectStreamCardsSettingsDef public readonly partial struct CustomActionsSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public CustomActionsSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.Mutable.cs index 1b6324b9169..f49b5036481 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.Mutable.cs @@ -380,6 +380,36 @@ public bool RemoveShowFirstActionInFooter() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ShowFirstActionInFooterUtf8, out IJsonDocument? _, out int _)) + { + SetShowFirstActionInFooter(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ObjectStreamCardsSettingsDef.ShowFirstActionInFooterEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.ShowFirstActionInFooterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.ShowFirstActionInFooterEntity.cs index 9536f82392a..66faa16f80e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.ShowFirstActionInFooterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.ShowFirstActionInFooterEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ShowFirstActionInFooterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.cs index 084bde856e2..6160f4a4fc8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectStreamCardsSettingsDef.cs @@ -386,6 +386,12 @@ private void CheckValidInstance() public ObjectStreamCardsSettingsDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectType.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectType.cs index af8add19ce1..02357d695aa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectType.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ObjectType.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ObjectType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.Mutable.cs index eafb88e4050..041441a426e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.Mutable.cs @@ -326,6 +326,31 @@ public bool RemoveVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.cs index cc4e4687f56..d9295643ea4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.OpenSource.cs @@ -332,6 +332,12 @@ private void CheckValidInstance() public OpenSource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.ActionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.ActionEntity.cs index a5da1d753a3..32c85b183e9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.ActionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.ActionEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ActionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.AdditionalParametersEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.AdditionalParametersEntity.cs index 14d911d74b7..4853cf6992a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.AdditionalParametersEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.AdditionalParametersEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public AdditionalParametersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.Mutable.cs index aa88f107ac6..3bc7c984665 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.Mutable.cs @@ -419,6 +419,31 @@ public void SetSemanticObject(scoped in Corvus.Ui5ManifestBenchmark.Current.Ui5M _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsABusinessEntityEGEmployee.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsABusinessEntityEGEmployee.cs index 67b5693b1d6..2fe4513002a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsABusinessEntityEGEmployee.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsABusinessEntityEGEmployee.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RepresentsABusinessEntityEGEmployee Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.Mutable.cs index 63c7afa176c..42fd4caaa4c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.Mutable.cs @@ -308,6 +308,37 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.Mutable __corvusValue)) + { + __corvusValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.FormatEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.FormatEntity.cs index 99f9b93bc76..dc176fea34f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.FormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.FormatEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public FormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.Mutable.cs index 9e82845cdfa..36263d15b54 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.Mutable.cs @@ -279,6 +279,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.cs index d63620f5f2a..76ec5cb72b6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.ValueEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.cs index 97b7e6edb85..244415861d8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.W1Entity.cs @@ -309,6 +309,12 @@ private void CheckValidInstance() public W1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.cs index 3406f46fb9e..0c337a6c60b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.RepresentsParametersOfNavigationIntents.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public RepresentsParametersOfNavigationIntents Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.cs index ac7213018f5..e4bc159b5cf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.RequiredActionAndSemanticObject.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public RequiredActionAndSemanticObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.cs index a7000227203..0e881f6a78b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Outbound.cs @@ -392,6 +392,12 @@ private void CheckValidInstance() public Outbound Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.Mutable.cs index 684a1dded86..661d3f48371 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.Mutable.cs @@ -1000,6 +1000,49 @@ public bool RemoveRoutingSpec() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ComponentDef.Mutable __corvusComponent)) + { + __corvusComponent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NavigationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.NavigationDef.Mutable __corvusNavigation)) + { + __corvusNavigation.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoutingSpecUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingSpecDef.Mutable __corvusRoutingSpec)) + { + __corvusRoutingSpec.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.PagesArrayArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.PagesArrayArray.cs index 191ffe9723b..094ff71a8f0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.PagesArrayArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.PagesArrayArray.cs @@ -23,11 +23,13 @@ public readonly partial struct PagesArray public readonly partial struct PagesArrayArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public PagesArrayArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.cs index 5eedb9372b8..8f377a3cd41 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesArray.cs @@ -477,6 +477,12 @@ private void CheckValidInstance() public PagesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.Mutable.cs index 84a5e3742e2..f7bffe9cef8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.Mutable.cs @@ -1000,6 +1000,49 @@ public bool RemoveRoutingSpec() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ComponentUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ComponentDef.Mutable __corvusComponent)) + { + __corvusComponent.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NavigationUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.NavigationDef.Mutable __corvusNavigation)) + { + __corvusNavigation.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RoutingSpecUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingSpecDef.Mutable __corvusRoutingSpec)) + { + __corvusRoutingSpec.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.PagesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.PagesEntity.cs index 9291b6c4aa0..ed1bf2f7905 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.PagesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.PagesEntity.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public PagesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.cs index faf3aab9b76..991d4e1f397 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PagesMap.cs @@ -477,6 +477,12 @@ private void CheckValidInstance() public PagesMap Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Parameters.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Parameters.cs index 454ce177333..fd69c83a77f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Parameters.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Parameters.cs @@ -344,6 +344,12 @@ private void CheckValidInstance() public Parameters Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.Mutable.cs index d9fddf80fc7..4fb31fe1d42 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.Mutable.cs @@ -207,6 +207,36 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TypeUtf8, out IJsonDocument? _, out int _)) + { + SetType(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.TypeEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.TypeEntity.cs index b555761f577..7009499353d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.TypeEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.cs index 6a5955666d1..53f313e55ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.cs @@ -294,6 +294,12 @@ private void CheckValidInstance() public DataLabelEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.Mutable.cs index 9dc09a77fd6..28c8d3751c7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.Mutable.cs @@ -373,6 +373,42 @@ public bool RemoveMarkerSize() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsSmoothedUtf8, out IJsonDocument? _, out int _)) + { + SetIsSmoothed(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.PlotAreaDef.RepresentsWhetherSmootherCurvesAreRequiredOrNot.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DataLabelUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.PlotAreaDef.DataLabelEntity.Mutable __corvusDataLabel)) + { + __corvusDataLabel.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.RepresentsWhetherSmootherCurvesAreRequiredOrNot.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.RepresentsWhetherSmootherCurvesAreRequiredOrNot.cs index 439742f5efe..fbf15b18cf2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.RepresentsWhetherSmootherCurvesAreRequiredOrNot.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.RepresentsWhetherSmootherCurvesAreRequiredOrNot.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsWhetherSmootherCurvesAreRequiredOrNot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.cs index 8d8827ae596..14580a64e26 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.PlotAreaDef.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public PlotAreaDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.Mutable.cs index 24615244cfd..09fee37b41b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.Mutable.cs @@ -337,6 +337,31 @@ public bool RemoveText() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsProgressIndicatorPercentValue.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsProgressIndicatorPercentValue.cs index b04612c14f9..72dd8c4cde4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsProgressIndicatorPercentValue.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsProgressIndicatorPercentValue.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RepresentsProgressIndicatorPercentValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsStateColor.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsStateColor.cs index 06e6d17474e..2b85bb31018 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsStateColor.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.RepresentsStateColor.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public RepresentsStateColor Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.cs index dcf540d54ba..3de7f86ad8d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ProgressIndicator.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public ProgressIndicator Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.Mutable.cs index 474861d0842..ed682e5ddfc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.Mutable.cs @@ -241,6 +241,31 @@ public bool RemoveEntitySets() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.cs index 967aa6e9619..c73cce34b59 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RefreshStrategiesPropDef.cs @@ -287,6 +287,12 @@ private void CheckValidInstance() public RefreshStrategiesPropDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.MapOfRequestsToBeBatched.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.MapOfRequestsToBeBatched.cs index ecb5c38f671..1d3974f9178 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.MapOfRequestsToBeBatched.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.MapOfRequestsToBeBatched.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public MapOfRequestsToBeBatched Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.Mutable.cs index 2e350f3db77..0fa34d62875 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.Mutable.cs @@ -938,6 +938,37 @@ public bool RemoveWithCredentials() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.CacheValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Cache.Mutable __corvusCacheValue)) + { + __corvusCacheValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RepresentsHttpHeaders.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RepresentsHttpHeaders.cs index 7be71e2f792..f02245b84f1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RepresentsHttpHeaders.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RepresentsHttpHeaders.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public RepresentsHttpHeaders Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RetryAfterEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RetryAfterEntity.cs index 0c1e96f7907..eb885a4a4b7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RetryAfterEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.RetryAfterEntity.cs @@ -485,6 +485,12 @@ private void CheckValidInstance() public RetryAfterEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.OneOf0Entity.cs index 3fbe7a6db02..4256489cb89 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.cs index f8b41225c30..97f5c6d4808 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheHttpMethod.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheHttpMethod Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.OneOf0Entity.cs index 9cdf5cfa3b7..0775cb1005a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.OneOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.cs index 9fc857fc188..c59678e23f7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TheModeOfTheRequest.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TheModeOfTheRequest Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.OneOf0Entity.cs index 0e476bf0474..ab0e4080404 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.OneOf0Entity.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.cs index 6dc499b8274..1e9dc657d87 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.TimeoutEntity.cs @@ -512,6 +512,12 @@ private void CheckValidInstance() public TimeoutEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.OneOf0Entity.cs index 1ab8c899d75..1a06a729d14 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.OneOf0Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.cs index c81c96b1f9c..3027a9a1dd2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.WithCredentialsEntity.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public WithCredentialsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.cs index 0dcab97e506..94da9c48027 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Request.cs @@ -490,6 +490,12 @@ private void CheckValidInstance() public Request Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariant.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariant.cs index 66517f957a3..0a9e0a261cc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariant.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariant.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public ResizableLayoutVariant Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.Mutable.cs index c7fc3926905..50cbd50840b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.Mutable.cs @@ -425,6 +425,36 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.VisibleUtf8, out IJsonDocument? _, out int _)) + { + SetVisible(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.ResizableLayoutVariantCardProperties.RepresentsTheVisibilityOfTheCard.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.RepresentsTheVisibilityOfTheCard.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.RepresentsTheVisibilityOfTheCard.cs index fed9a8c1f12..3f23e63d242 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.RepresentsTheVisibilityOfTheCard.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.RepresentsTheVisibilityOfTheCard.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public RepresentsTheVisibilityOfTheCard Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.cs index e934deeb589..40ee0f33dbd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResizableLayoutVariantCardProperties.cs @@ -388,6 +388,12 @@ private void CheckValidInstance() public ResizableLayoutVariantCardProperties Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.Mutable.cs index 112f70b5e30..54a92e9b3f3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.Mutable.cs @@ -268,6 +268,31 @@ public void SetUriValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.cs index c09e0d23614..89c4dc54bf1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.RequiredUriEntity.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public RequiredUriEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.cs index c9e909847ea..cb39f0b7101 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.JsRequiredUriEntiArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Resource public readonly partial struct JsRequiredUriEntiArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsRequiredUriEntiArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.Mutable.cs index 1b737af9e0a..15dd457ebf4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.Mutable.cs @@ -406,6 +406,31 @@ public bool RemoveJs() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.Mutable.cs index f64d77d27a2..c5384d4df0d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.Mutable.cs @@ -329,6 +329,31 @@ public void SetUriValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.cs index 5bfdbf7847d..7c305715fec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.RequiredUriEntity.cs @@ -380,6 +380,12 @@ private void CheckValidInstance() public RequiredUriEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.cs index 5810158f304..22dd43cf85e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.RequiredUriEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Resource public readonly partial struct RequiredUriEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public RequiredUriEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.cs index 7db8539958d..48074f8b952 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Resource.cs @@ -371,6 +371,12 @@ private void CheckValidInstance() public Resource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResourceRoot.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResourceRoot.cs index 2309e09db74..799e70ba0bd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResourceRoot.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.ResourceRoot.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ResourceRoot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.ConfigureTheTargetsForAsynchronousLoading.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.ConfigureTheTargetsForAsynchronousLoading.cs index 8943056187f..0d97f127950 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.ConfigureTheTargetsForAsynchronousLoading.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.ConfigureTheTargetsForAsynchronousLoading.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public ConfigureTheTargetsForAsynchronousLoading Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.Mutable.cs index 6a7ba5066d5..ee5cc3d8f4d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.Mutable.cs @@ -467,6 +467,36 @@ public void SetViewName(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsyncUtf8, out IJsonDocument? _, out int _)) + { + SetAsync(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RootViewDef.RequiredViewName.ConfigureTheTargetsForAsynchronousLoading.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.TypeEntity.cs index 3b51fd48f18..7babe40cdfc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.TypeEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.cs index ece81ccaa9b..9a903650e8e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.RequiredViewName.cs @@ -428,6 +428,12 @@ private void CheckValidInstance() public RequiredViewName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.cs index 7d895c7907f..76cdb3881c6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDef.cs @@ -425,6 +425,12 @@ private void CheckValidInstance() public RootViewDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.ConfigureTheTargetsForAsynchronousLoading.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.ConfigureTheTargetsForAsynchronousLoading.cs index 59cbcf48e37..e4dab205bf1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.ConfigureTheTargetsForAsynchronousLoading.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.ConfigureTheTargetsForAsynchronousLoading.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public ConfigureTheTargetsForAsynchronousLoading Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.Mutable.cs index 92afaf8dc68..7a98bf40431 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.Mutable.cs @@ -454,6 +454,36 @@ public void SetViewName(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsyncUtf8, out IJsonDocument? _, out int _)) + { + SetAsync(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RootViewDefFlexEnabled.ConfigureTheTargetsForAsynchronousLoading.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.TypeEntity.cs index e130298543d..e399b9ffcaa 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.TypeEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.cs index 3ce40a8495f..393d870a61f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RootViewDefFlexEnabled.cs @@ -434,6 +434,12 @@ private void CheckValidInstance() public RootViewDefFlexEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.Mutable.cs index 677fd47b3db..6befcf30579 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.Mutable.cs @@ -606,6 +606,31 @@ public bool RemoveTitleTarget() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.Mutable.cs index d8e36c10a0b..493aa26f073 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.Mutable.cs @@ -269,6 +269,31 @@ public void SetName(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.Sou _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.cs index 4c14e94b984..8c4a4e25fdd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.RequiredName.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.cs index be745c1bdc7..6fb113632eb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Route.cs @@ -491,6 +491,12 @@ private void CheckValidInstance() public Route Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.Items0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.Items0Entity.cs index 675b2bc2ecd..1540254b289 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.Items0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.Items0Entity.cs @@ -424,6 +424,12 @@ private void CheckValidInstance() public Items0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.cs index 45c3eb26acf..0c9b72c5671 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.OneOf0Array.cs @@ -23,11 +23,13 @@ public readonly partial struct RouteTarget public readonly partial struct OneOf0Array #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public ArrayEnumerator EnumerateArray() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public OneOf0Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.cs index 1e446343509..1743e665161 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTarget.cs @@ -476,6 +476,12 @@ private void CheckValidInstance() public RouteTarget Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.Mutable.cs index 38c98bf91f3..da2b9371d74 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.Mutable.cs @@ -410,6 +410,36 @@ public bool RemovePropagateTitle() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropagateTitleUtf8, out IJsonDocument? _, out int _)) + { + SetPropagateTitle(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RouteTargetObject.PropagateTitleEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.PropagateTitleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.PropagateTitleEntity.cs index 9027493209c..7f0062ec8bd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.PropagateTitleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.PropagateTitleEntity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public PropagateTitleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.cs index f52a4fab19e..1f116b33e35 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteTargetObject.cs @@ -407,6 +407,12 @@ private void CheckValidInstance() public RouteTargetObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.Mutable.cs index b0900c15908..db919bfe935 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.Mutable.cs @@ -515,6 +515,31 @@ public bool RemoveTitleTarget() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.cs index b4a0686ab66..9b19345fbcf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RouteWithoutName.cs @@ -431,6 +431,12 @@ private void CheckValidInstance() public RouteWithoutName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.Mutable.cs index 209be5fca4e..1233b298123 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.Mutable.cs @@ -513,6 +513,37 @@ public bool RemoveTargets() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable __corvusConfig)) + { + __corvusConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs index 3bbed8c3064..72da7751615 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs index fa6d9c4b523..d981b69c326 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs @@ -582,6 +582,47 @@ public bool RemoveViewPath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsyncUtf8, out IJsonDocument? _, out int _)) + { + SetAsync(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropagateTitleUtf8, out IJsonDocument? _, out int _)) + { + SetPropagateTitle(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.PropagateTitleEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BypassedUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable __corvusBypassed)) + { + __corvusBypassed.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.PropagateTitleEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.PropagateTitleEntity.cs index 3b6f7d926a9..db8ff8cc0ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.PropagateTitleEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.PropagateTitleEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public PropagateTitleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs index d14907e16b5..e0c3450e2e8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs @@ -237,6 +237,31 @@ public void SetTarget(in Corvus.Ui5ManifestBenchmark.Current.Ui5Manife _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs index e0017b974ae..a1273f804f4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs @@ -304,6 +304,12 @@ private void CheckValidInstance() public RequiredTarget Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs index 915005bb498..84cd1a7f8e4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs @@ -448,6 +448,12 @@ private void CheckValidInstance() public AllOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs index 97a54485429..689c0b0b28b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs @@ -1312,6 +1312,47 @@ public bool RemoveViewType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsyncUtf8, out IJsonDocument? _, out int _)) + { + SetAsync(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropagateTitleUtf8, out IJsonDocument? _, out int _)) + { + SetPropagateTitle(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.PropagateTitleEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BypassedUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable __corvusBypassed)) + { + __corvusBypassed.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs index 140018e96a9..dd15a8fda96 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs @@ -697,6 +697,12 @@ private void CheckValidInstance() public RepresentsTheDefaultPropertiesDefinedForRouteAndTarget Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs index 0e023e24a8c..23ebc3cd285 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs @@ -1137,6 +1137,31 @@ public bool RemoveViewType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.Mutable.cs index fc86d5b6b22..fc9725fc8a6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.Mutable.cs @@ -407,6 +407,31 @@ public bool RemoveViewPath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.cs index 5eff9f4de6e..04e9fe1de0b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewName.cs @@ -413,6 +413,12 @@ private void CheckValidInstance() public RequiredViewName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs index dc2d4cc6437..024c22bce48 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs @@ -657,6 +657,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.Mutable.cs index 3092a05a5ca..06f6686a44a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.Mutable.cs @@ -475,6 +475,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.RepresentsTheTypeOfTheTypeViewOrComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.RepresentsTheTypeOfTheTypeViewOrComponent.cs index 6d66a28a40b..e93f9c2c3f0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.RepresentsTheTypeOfTheTypeViewOrComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.RepresentsTheTypeOfTheTypeViewOrComponent.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheTypeViewOrComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.cs index 393d9811d76..00a29a9a910 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.cs @@ -436,6 +436,12 @@ private void CheckValidInstance() public RequiredName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.Mutable.cs index f51b41a3495..f7ccc08e9b5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.Mutable.cs @@ -398,6 +398,31 @@ public void SetUsage(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs index 978dd9f904a..510a5b72c05 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheTypeComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.cs index 22c0991c663..d04e22cadf0 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.cs @@ -418,6 +418,12 @@ private void CheckValidInstance() public RequiredTypeAndUsage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs index dec59673dea..b9dfea505f8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs index ef5b79619e3..d335b45370d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs @@ -986,6 +986,31 @@ public bool RemoveViewType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs index 81f5ede307f..eccab3e57f5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs @@ -627,6 +627,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.cs index 8276771a1db..a5bfec26f9a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.cs @@ -487,6 +487,12 @@ private void CheckValidInstance() public SSEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.cs index 3e7b8e9fc5f..0a2209c0948 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public RepresentsTheDefinitionOfTargets Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.OneOf1Entity.cs index c6257fc2ed7..043bff63fdd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.OneOf1Entity.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.RouteArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.RouteArray.cs index 3bf96c732ad..5081e257d63 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.RouteArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.RouteArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RoutesEntity public readonly partial struct RouteArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RouteArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.cs index 0516829d0c8..d00c8fd36d2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.RoutesEntity.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public RoutesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.cs index ac6c9e64569..d37d6c824bc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Routing.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public Routing Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.Mutable.cs index a84cf3f5cf4..0018c7057ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.Mutable.cs @@ -513,6 +513,37 @@ public bool RemoveTargets() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ConfigUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable __corvusConfig)) + { + __corvusConfig.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs index a1f9377674c..80a37fe84f8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs index 2c2b1f6cca3..caf271b8eeb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs @@ -516,6 +516,42 @@ public bool RemoveViewPath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsyncUtf8, out IJsonDocument? _, out int _)) + { + SetAsync(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BypassedUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable __corvusBypassed)) + { + __corvusBypassed.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs index 010ffff7036..4432a7149de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable.cs @@ -237,6 +237,31 @@ public void SetTarget(in Corvus.Ui5ManifestBenchmark.Current.Ui5Manife _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs index 990f971e88d..4ba94d31201 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.cs @@ -304,6 +304,12 @@ private void CheckValidInstance() public RequiredTarget Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs index c2f6e7bb5c5..e7238812af7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public AllOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs index 1a96c6443fb..0bac174461a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.Mutable.cs @@ -1246,6 +1246,42 @@ public bool RemoveViewType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AsyncUtf8, out IJsonDocument? _, out int _)) + { + SetAsync(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BypassedUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.RequiredTarget.Mutable __corvusBypassed)) + { + __corvusBypassed.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs index 28503beae2a..ee7ec20ee60 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs @@ -676,6 +676,12 @@ private void CheckValidInstance() public RepresentsTheDefaultPropertiesDefinedForRouteAndTarget Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs index e0a01ea2434..33627dbb4f5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.Mutable.cs @@ -1126,6 +1126,31 @@ public bool RemoveViewType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.Mutable.cs index 2cae3dec833..6b4abe150a8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.Mutable.cs @@ -396,6 +396,31 @@ public bool RemoveViewPath() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.cs index 11ad788894d..9eb26e777c8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.RequiredViewIdAndViewName.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public RequiredViewIdAndViewName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs index c617873f462..00c6dbf700f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.cs @@ -660,6 +660,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.Mutable.cs index 0b81ccf889b..233d052a8ca 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.Mutable.cs @@ -464,6 +464,31 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.cs index 6c005416c58..0be222c0124 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.cs @@ -439,6 +439,12 @@ private void CheckValidInstance() public RequiredIdAndName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.Mutable.cs index 90898035145..7c3bbba495b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.Mutable.cs @@ -387,6 +387,31 @@ public void SetUsage(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.cs index 55c688d9db6..a1731e3ce56 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.cs @@ -421,6 +421,12 @@ private void CheckValidInstance() public RequiredIdAndTypeAndUsage Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs index 009b28f926e..2b40dbe43de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public AllOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs index 6a6b25ee5ed..b86fd1f21cb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs @@ -986,6 +986,31 @@ public bool RemoveViewType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs index 7975fe19c47..7e85c12ae97 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs @@ -627,6 +627,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.cs index 19e9c029f0b..be748e8518f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.cs @@ -487,6 +487,12 @@ private void CheckValidInstance() public SSEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SS_._OneOf1Entity.AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SS_._OneOf1Entity.AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.cs index a36a7833344..e2a2a16729d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SS_._OneOf1Entity.AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SS_._OneOf1Entity.AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheTypeViewOrComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.cs index ac3f1edf148..680baa178db 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public RepresentsTheDefinitionOfTargets Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets_._OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets_._OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs index 49dedb0b63f..fc56240a281 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets_._OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets_._OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfTheTypeComponent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.OneOf1Entity.cs index ff3278a770b..c563709998c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.OneOf1Entity.cs @@ -446,6 +446,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.RouteArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.RouteArray.cs index 4d4b33a3341..00113b6ca2f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.RouteArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.RouteArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RoutesEntity public readonly partial struct RouteArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RouteArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.cs index 3d990634daf..1666ce88b86 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.cs @@ -419,6 +419,12 @@ private void CheckValidInstance() public RoutesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.cs index aec1cad7770..692f3e419a4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingFlexEnabled.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public RoutingFlexEnabled Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.Mutable.cs index f4f355c65b3..48f08b1b24d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.Mutable.cs @@ -590,6 +590,31 @@ public bool RemoveTypeImageUrl() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.cs index 8c7862964f4..1a445c39b9b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.RoutingSpecDef.cs @@ -416,6 +416,12 @@ private void CheckValidInstance() public RoutingSpecDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DefinitionsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DefinitionsEntity.cs index bdd7ccad9c3..067f5d6416c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DefinitionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DefinitionsEntity.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public DefinitionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.AdditionalPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.AdditionalPropertiesEntity.cs index 143504d4768..ffa5f541c57 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.AdditionalPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.AdditionalPropertiesEntity.cs @@ -463,6 +463,12 @@ private void CheckValidInstance() public AdditionalPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.cs index 66759efe3ed..30199d63d94 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.DependenciesEntity.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public DependenciesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ExamplesJsoArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ExamplesJsoArray.cs index 4f0a0a4b5ae..3b17d580c9d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ExamplesJsoArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ExamplesJsoArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Schema public readonly partial struct ExamplesJsoArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public ExamplesJsoArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ItemsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ItemsEntity.cs index 9aaea9a325b..297751ee3bb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ItemsEntity.cs @@ -471,6 +471,12 @@ private void CheckValidInstance() public ItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.JsonElementArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.JsonElementArray.cs index 0af51df0bce..9835a36382c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.JsonElementArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.JsonElementArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Schema public readonly partial struct JsonElementArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public JsonElementArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.MultipleOfEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.MultipleOfEntity.cs index f78df6f7ea9..ea5dd6b8236 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.MultipleOfEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.MultipleOfEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public MultipleOfEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.Mutable.cs index 780781842c3..456e0c7a0ac 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.Mutable.cs @@ -3862,6 +3862,159 @@ public bool RemoveWriteOnly() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AdditionalItemsUtf8, out IJsonDocument? _, out int _)) + { + SetAdditionalItems(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AdditionalPropertiesUtf8, out IJsonDocument? _, out int _)) + { + SetAdditionalProperties(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContainsUtf8, out IJsonDocument? _, out int _)) + { + SetContains(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefinitionsUtf8, out IJsonDocument? _, out int _)) + { + SetDefinitions(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefinitionsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out IJsonDocument? _, out int _)) + { + SetElse(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IfUtf8, out IJsonDocument? _, out int _)) + { + SetIf(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ItemsUtf8, out IJsonDocument? _, out int _)) + { + SetItems(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.ItemsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NotUtf8, out IJsonDocument? _, out int _)) + { + SetNot(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PatternPropertiesUtf8, out IJsonDocument? _, out int _)) + { + SetPatternProperties(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.PatternPropertiesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropertiesUtf8, out IJsonDocument? _, out int _)) + { + SetProperties(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.PropertiesEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropertyNamesUtf8, out IJsonDocument? _, out int _)) + { + SetPropertyNames(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ReadOnlyUtf8, out IJsonDocument? _, out int _)) + { + SetReadOnly(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.ReadOnlyEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.RequiredUtf8, out IJsonDocument? _, out int _)) + { + SetRequired(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.StringArray.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ThenUtf8, out IJsonDocument? _, out int _)) + { + SetThen(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.UniqueItemsUtf8, out IJsonDocument? _, out int _)) + { + SetUniqueItems(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.UniqueItemsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.WriteOnlyUtf8, out IJsonDocument? _, out int _)) + { + SetWriteOnly(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.WriteOnlyEntity.DefaultInstance); + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AdditionalItemsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusAdditionalItems)) + { + __corvusAdditionalItems.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.AdditionalPropertiesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusAdditionalProperties)) + { + __corvusAdditionalProperties.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ContainsUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusContains)) + { + __corvusContains.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ElseUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusElse)) + { + __corvusElse.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IfUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusIf)) + { + __corvusIf.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.NotUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusNot)) + { + __corvusNot.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PropertyNamesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusPropertyNames)) + { + __corvusPropertyNames.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ThenUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Schema.Mutable __corvusThen)) + { + __corvusThen.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeInteger.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeInteger.cs index 82000058240..b7b30d44ec3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeInteger.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeInteger.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public NonNegativeInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.DefaultValueType0.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.DefaultValueType0.cs index d67b7e6d2f7..317cf99806d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.DefaultValueType0.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.DefaultValueType0.cs @@ -411,6 +411,12 @@ private void CheckValidInstance() public DefaultValueType0 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.cs index 4cf4c447635..31217e1e31f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.NonNegativeIntegerDefault0.cs @@ -435,6 +435,12 @@ private void CheckValidInstance() public NonNegativeIntegerDefault0 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PatternPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PatternPropertiesEntity.cs index 34fa8c26220..551ce8943bf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PatternPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PatternPropertiesEntity.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public PatternPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PropertiesEntity.cs index 587039d90ca..51b0b3376a4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.PropertiesEntity.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public PropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ReadOnlyEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ReadOnlyEntity.cs index a9089061ce3..6d974291e1e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ReadOnlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.ReadOnlyEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public ReadOnlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SchemaArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SchemaArray.cs index 30e0832f458..1ffff76c242 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SchemaArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SchemaArray.cs @@ -23,11 +23,13 @@ public readonly partial struct Schema public readonly partial struct SchemaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public SchemaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SimpleTypes.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SimpleTypes.cs index 96def6c0caf..33511a85835 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SimpleTypes.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.SimpleTypes.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public SimpleTypes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.StringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.StringArray.cs index ee7e6ce6fe3..1b931b08ab6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.StringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.StringArray.cs @@ -33,11 +33,13 @@ public readonly partial struct Schema public readonly partial struct StringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -88,6 +90,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -301,6 +318,12 @@ private void CheckValidInstance() public StringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.SimpleTypesArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.SimpleTypesArray.cs index d176cbe0b26..f4b6d4e6f4b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.SimpleTypesArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.SimpleTypesArray.cs @@ -25,11 +25,13 @@ public readonly partial struct TypeEntity public readonly partial struct SimpleTypesArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public SimpleTypesArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.cs index e6cbca90572..68d2bf28a1f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.TypeEntity.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.UniqueItemsEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.UniqueItemsEntity.cs index c1eafdfc85e..173d81697ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.UniqueItemsEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.UniqueItemsEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public UniqueItemsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.WriteOnlyEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.WriteOnlyEntity.cs index 85645e3fb7c..4dbbdfed2d3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.WriteOnlyEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.WriteOnlyEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public WriteOnlyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.cs index a8f2fbd49a7..bf66bfefbee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Schema.cs @@ -1127,6 +1127,12 @@ private void CheckValidInstance() public Schema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Semanticversion.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Semanticversion.cs index 59ad2382588..aa147e6baed 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Semanticversion.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Semanticversion.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public Semanticversion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.IndicatesWhetherTheServiceOptionalOrNot.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.IndicatesWhetherTheServiceOptionalOrNot.cs index 08d85b67a6c..fe54a35b324 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.IndicatesWhetherTheServiceOptionalOrNot.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.IndicatesWhetherTheServiceOptionalOrNot.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public IndicatesWhetherTheServiceOptionalOrNot Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.Mutable.cs index 0f815005678..2d047cfa369 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.Mutable.cs @@ -333,6 +333,36 @@ public bool RemoveOptional() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionalUtf8, out IJsonDocument? _, out int _)) + { + SetOptional(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Service.IndicatesWhetherTheServiceOptionalOrNot.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.RepresentsTheNameOfTheServiceFactory.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.RepresentsTheNameOfTheServiceFactory.cs index c6d0ef3a6f3..5020d3c0e3b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.RepresentsTheNameOfTheServiceFactory.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.RepresentsTheNameOfTheServiceFactory.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheNameOfTheServiceFactory Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.cs index bc7a844f7ad..0f2d76d81fc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Service.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public Service Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.Mutable.cs index 1293868835d..6a46eccfac9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.Mutable.cs @@ -369,6 +369,31 @@ public bool RemoveSchemaName() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.cs index a418769b96f..0b4660e3b1d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.ACatalogObjectOfAnInADataSource.cs @@ -349,6 +349,12 @@ private void CheckValidInstance() public ACatalogObjectOfAnInADataSource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.cs index be424a3142a..0d6edddd921 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.DictionaryOfCatalogObjectsOfferedByTheDatasource.cs @@ -346,6 +346,12 @@ private void CheckValidInstance() public DictionaryOfCatalogObjectsOfferedByTheDatasource Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.JsonStringArray.cs index 5e2f7a4a1df..4843f91f510 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Setting public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.MaxAgeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.MaxAgeEntity.cs index 84279402566..56fdc4b42c8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.MaxAgeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.MaxAgeEntity.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public MaxAgeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.Mutable.cs index 33ae855d1b4..6dc2f3d73c7 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.Mutable.cs @@ -680,6 +680,31 @@ public bool RemoveOdataVersion() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.RepresentsVersionOfOData20IsDefault.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.RepresentsVersionOfOData20IsDefault.cs index ea7f9ab7608..ebae41a79dd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.RepresentsVersionOfOData20IsDefault.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.RepresentsVersionOfOData20IsDefault.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsVersionOfOData20IsDefault Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.cs index 9ea0bbf4a8b..0c2eaa13f5d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Setting.cs @@ -465,6 +465,12 @@ private void CheckValidInstance() public Setting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.AdditionalParametersEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.AdditionalParametersEntity.cs index 3f3f3b94293..90c53bbe1a9 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.AdditionalParametersEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.AdditionalParametersEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public AdditionalParametersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.Mutable.cs index abc9fe7d6da..e5978cfbcb6 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.Mutable.cs @@ -280,6 +280,31 @@ public void SetParameters(in Corvus.Ui5ManifestBenchmark.Current.Ui5Ma _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.FormatEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.FormatEntity.cs index 92987aedc83..ef1f41f11fd 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.FormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.FormatEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public FormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.Mutable.cs index 133436ff225..a1ac57df687 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.Mutable.cs @@ -374,6 +374,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.JsonStringArray.cs index 5d51ff102ea..239a424756b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.JsonStringArray.cs @@ -36,11 +36,13 @@ public readonly partial struct ValueEntity public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -90,6 +92,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -303,6 +320,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.cs index 3d8990be113..856e1b8e67c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.ValueEntity.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.cs index b7a0e0efb33..b1ef650dd25 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public LauncherValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.Mutable.cs index cbe272f567f..e24f77558cf 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.Mutable.cs @@ -576,6 +576,49 @@ public bool RemoveRequired() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.Mutable __corvusDefaultValue)) + { + __corvusDefaultValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FilterUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.Mutable __corvusFilter)) + { + __corvusFilter.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LauncherValueUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.LauncherValueEntity.Mutable __corvusLauncherValue)) + { + __corvusLauncherValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.FormatEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.FormatEntity.cs index 24a1ebcbc08..eda8ddd78ad 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.FormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.FormatEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public FormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.Mutable.cs index f4d33ac78cf..d71bc787304 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.Mutable.cs @@ -342,6 +342,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.cs index 1878fe54089..2acdbcdc18d 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf0Entity.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.FormatEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.FormatEntity.cs index 96c679f1be4..ae1a94a91de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.FormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.FormatEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public FormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.Mutable.cs index bec2e16bcc4..c0ba8e726d4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.Mutable.cs @@ -342,6 +342,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.ValueEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.ValueEntity.cs index d4d6da22c9a..0d6aff4c0de 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.ValueEntity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.cs index ae51b3b1dc2..95e90cda600 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf1Entity.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.Mutable.cs index d54b8959501..0449cde9122 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.Mutable.cs @@ -342,6 +342,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.cs index eb2877b5ff9..a1256df8571 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.AnyOf2Entity.cs @@ -379,6 +379,12 @@ private void CheckValidInstance() public AnyOf2Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.FormatEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.FormatEntity.cs index b178cf0f0b2..a66a99f425a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.FormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.FormatEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public FormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.Mutable.cs index f235d61b714..2d390e69c33 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.Mutable.cs @@ -320,6 +320,31 @@ public void SetValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.cs index 0ffdf9b826c..1aedbda01ee 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsADefaultValue.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public RepresentsADefaultValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.FormatEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.FormatEntity.cs index 6d299698182..318df179064 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.FormatEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.FormatEntity.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public FormatEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.Mutable.cs index cef62ce4c97..ca239074429 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.Mutable.cs @@ -266,6 +266,31 @@ public void SetValue(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonString.So _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.cs index 70528cef0bd..5a27778c00c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.RepresentsAFilterOnlyIfInputParameterMatchesFilter.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RepresentsAFilterOnlyIfInputParameterMatchesFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.cs index e800585b528..14531572e69 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.W1Entity.cs @@ -370,6 +370,12 @@ private void CheckValidInstance() public W1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.cs index e44e9a3b338..5a025b9909c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.ParametersEntity.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public ParametersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.cs index 0db84cf993a..2edd552c198 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SignatureDef.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public SignatureDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleBinding.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleBinding.cs index ddada60b80b..45c661d551c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleBinding.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleBinding.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SimpleBinding Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.Mutable.cs index a2b01ea64a1..1af7a0ccf11 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.Mutable.cs @@ -271,6 +271,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.cs index c6e57ed688b..02d1afe45c3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.SimpleIcon.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SimpleIcon Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.State.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.State.cs index 53e75360c59..a1ec7f0bd29 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.State.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.State.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public State Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.Mutable.cs index 54e80ff278b..24a2c9eb271 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.Mutable.cs @@ -307,6 +307,31 @@ public bool RemoveVisible() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.RepresentsStatusText.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.RepresentsStatusText.cs index 72da0297be4..a4fbc60f68a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.RepresentsStatusText.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.RepresentsStatusText.cs @@ -427,6 +427,12 @@ private void CheckValidInstance() public RepresentsStatusText Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.cs index 1913c369411..cc51aa9b8db 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Status.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public Status Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.Mutable.cs index d4f7f05aebb..d44e57ab6b4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.Mutable.cs @@ -299,6 +299,31 @@ public bool RemoveTranslationKey() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.cs index 69eb3f17181..d74d38d5c45 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.cs @@ -305,6 +305,12 @@ private void CheckValidInstance() public DefinesBindingInformation Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.Mutable.cs index 63cc2f500e1..fcf49bacd78 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.Mutable.cs @@ -241,6 +241,37 @@ public bool RemoveFormat() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FormatUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.StatusTextFormatter.DefinesBindingInformation.Mutable __corvusFormat)) + { + __corvusFormat.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.cs index 44849dea318..c874311e114 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.StatusTextFormatter.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public StatusTextFormatter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.Mutable.cs index d4d4ef1dd4d..97ab03af7d2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.Mutable.cs @@ -345,6 +345,43 @@ public bool RemoveTimeAxis() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.PlotAreaUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.PlotAreaDef.Mutable __corvusPlotArea)) + { + __corvusPlotArea.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.TimeAxisUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.TimeAxisDef.Mutable __corvusTimeAxis)) + { + __corvusTimeAxis.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.cs index 1ca13372240..8ea424725b3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public ChartPropertiesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.JsonObjectArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.JsonObjectArray.cs index 9e1aadaf6db..b266816a1b3 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.JsonObjectArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.JsonObjectArray.cs @@ -25,11 +25,13 @@ public readonly partial struct ColorPaletteEntity public readonly partial struct JsonObjectArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -79,6 +81,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -292,6 +309,12 @@ private void CheckValidInstance() public JsonObjectArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.cs index 5b964daaa75..3f69686bc7a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.ColorPaletteEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public ColorPaletteEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.Mutable.cs index 73d5f3f2c3a..194c3a87b3a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.Mutable.cs @@ -944,6 +944,37 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ChartPropertiesUtf8, out Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.TabSetting.ChartPropertiesEntity.Mutable __corvusChartProperties)) + { + __corvusChartProperties.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheAnnotationPath.cs index 579a3d963fa..5f7bb9c2a16 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheChartAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheChartAnnotationPath.cs index 85756e0dbe5..9b62b8fdc42 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheChartAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheChartAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheChartAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDataPointAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDataPointAnnotationPath.cs index c0611d347b6..5793dc65c40 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDataPointAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDataPointAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheDataPointAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs index 5b96c8da644..c3d6cfe41ab 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheDynamicSubtitleAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheDynamicSubtitleAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheIdentificationAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheIdentificationAnnotationPath.cs index 06a994ad665..f745f1e43cb 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheIdentificationAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheIdentificationAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheIdentificationAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsThePresentationAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsThePresentationAnnotationPath.cs index d3a72333c0a..3fe502fc444 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsThePresentationAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsThePresentationAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsThePresentationAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheSelectionAnnotationPath.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheSelectionAnnotationPath.cs index 80ff70300f2..a61e3d7cc2f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheSelectionAnnotationPath.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.RepresentsTheSelectionAnnotationPath.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheSelectionAnnotationPath Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.cs index a3f3954082c..f80e318caa2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TabSetting.cs @@ -554,6 +554,12 @@ private void CheckValidInstance() public TabSetting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Tag.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Tag.cs index 866bee1f218..d5c320e5689 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Tag.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Tag.cs @@ -21,11 +21,13 @@ public readonly partial struct Ui5ManifestSchema public readonly partial struct Tag #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public Tag Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.Mutable.cs index bc308ad1f46..be67bc18148 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.Mutable.cs @@ -908,6 +908,31 @@ public bool RemoveViewType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.RepresentsTheTypeOfViewThatIsGoingToBeCreated.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.RepresentsTheTypeOfViewThatIsGoingToBeCreated.cs index 1831ccaa1be..b65ff2a8ff2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.RepresentsTheTypeOfViewThatIsGoingToBeCreated.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.RepresentsTheTypeOfViewThatIsGoingToBeCreated.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public RepresentsTheTypeOfViewThatIsGoingToBeCreated Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf0Entity.cs index c0d48c3c4b0..852b1e627b8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf0Entity.cs @@ -327,6 +327,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf1Entity.cs index be6035600fe..dfecbe3abae 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.AnyOf1Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.cs index a1cc0e3a723..f387feeb636 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.TransitionEntity.cs @@ -374,6 +374,12 @@ private void CheckValidInstance() public TransitionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.ViewLevelEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.ViewLevelEntity.cs index 741247ea0bc..74c52f70b0f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.ViewLevelEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.ViewLevelEntity.cs @@ -404,6 +404,12 @@ private void CheckValidInstance() public ViewLevelEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.cs index c95624ab891..427e1e1e151 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Target.cs @@ -554,6 +554,12 @@ private void CheckValidInstance() public Target Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.Mutable.cs index 7a094220c7c..b9b819c3e7b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.Mutable.cs @@ -298,6 +298,31 @@ public bool RemoveSupportedLocales() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.cs index e1e387e6d71..84b9402ccdc 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleName.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public RequiredBundleName Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs index 6c11ea6813c..a7190f8971f 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.BundleUrlRelativeToEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public BundleUrlRelativeToEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.Mutable.cs index 6b60066e1df..1893209b61b 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.Mutable.cs @@ -364,6 +364,36 @@ public bool RemoveSupportedLocales() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleUrlRelativeToUtf8, out IJsonDocument? _, out int _)) + { + SetBundleUrlRelativeTo(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.BundleUrlRelativeToEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.cs index 165f3bc9670..033b01f56e2 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.RequiredBundleUrl.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public RequiredBundleUrl Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.cs index 60280be2e8a..7a0390dbea1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TerminologySetting.cs @@ -393,6 +393,12 @@ private void CheckValidInstance() public TerminologySetting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TextAlign.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TextAlign.cs index 8b0975cce2c..49bd52ea321 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TextAlign.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TextAlign.cs @@ -326,6 +326,12 @@ private void CheckValidInstance() public TextAlign Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.Mutable.cs index 23d7e6ef4ee..3a5abd9239c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.Mutable.cs @@ -314,6 +314,31 @@ public bool RemoveLevels() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.cs index e5a4dcca416..dee4dc6dea4 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.TimeAxisDef.cs @@ -365,6 +365,12 @@ private void CheckValidInstance() public TimeAxisDef Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.BundleUrlRelativeToEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.BundleUrlRelativeToEntity.cs index ccf72899fea..646066549af 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.BundleUrlRelativeToEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.BundleUrlRelativeToEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public BundleUrlRelativeToEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.DefaultBindingModeEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.DefaultBindingModeEntity.cs index e87c3291cdf..4f70ddc8b51 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.DefaultBindingModeEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.DefaultBindingModeEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public DefaultBindingModeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.EnhanceWithSettingArray.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.EnhanceWithSettingArray.cs index fd6fc4d5ee3..3985b55303a 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.EnhanceWithSettingArray.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.EnhanceWithSettingArray.cs @@ -28,11 +28,13 @@ public readonly partial struct Ui5setting public readonly partial struct EnhanceWithSettingArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public EnhanceWithSettingArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.Mutable.cs index 56386ae6566..2f2d79b0826 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.Mutable.cs @@ -848,6 +848,41 @@ public bool RemoveTerminologies() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BundleUrlRelativeToUtf8, out IJsonDocument? _, out int _)) + { + SetBundleUrlRelativeTo(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Ui5setting.BundleUrlRelativeToEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DefaultBindingModeUtf8, out IJsonDocument? _, out int _)) + { + SetDefaultBindingMode(Corvus.Ui5ManifestBenchmark.Current.Ui5ManifestSchema.Ui5setting.DefaultBindingModeEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs index 2c250bd9df6..03bc830d395 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs @@ -444,6 +444,12 @@ private void CheckValidInstance() public RepresentsTerminologiesWithAdditionalPropertiesFiles Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.cs index 8448ffeaf52..eb75dd310ec 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Ui5setting.cs @@ -507,6 +507,12 @@ private void CheckValidInstance() public Ui5setting Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.Mutable.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.Mutable.cs index ab41946e469..8b752bf1706 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.Mutable.cs @@ -443,6 +443,31 @@ public void SetUrl(scoped in Corvus.Ui5ManifestBenchmark.Current.JsonUriTemplate _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.cs index a6961b47da2..0e3db8822d5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Vendor.cs @@ -437,6 +437,12 @@ private void CheckValidInstance() public Vendor Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.VersionEntity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.VersionEntity.cs index 3f654c051de..d013ed6a7a1 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.VersionEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.OneOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.OneOf0Entity.cs index 8947314fd6c..e05386096ff 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.OneOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.OneOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public OneOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.cs index c067b3b0e0d..c3c921fe659 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.Visibility.cs @@ -409,6 +409,12 @@ private void CheckValidInstance() public Visibility Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.cs index b78dd2dab23..f50430f5d32 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/Ui5ManifestSchema.cs @@ -995,6 +995,12 @@ private void CheckValidInstance() public Ui5ManifestSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf0Entity.cs index c8e210c360f..ddf4ed3aa04 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf1Entity.cs index f8d14af46f8..23ccaf95176 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.cs index e1b76fc4d47..c45fbff8486 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalAlignment.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public VerticalAlignment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf0Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf0Entity.cs index f76d4052e02..8ce5996f5a8 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf0Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf0Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf0Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf1Entity.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf1Entity.cs index 8c1eb254891..c33de56f43e 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.AnyOf1Entity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public AnyOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.cs b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.cs index 14553fc632b..9dc58e04f1c 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.cs +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/VerticalContentAlignment.cs @@ -364,6 +364,12 @@ private void CheckValidInstance() public VerticalContentAlignment Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/corvusjson-jsonschema.lock index eda1d41a771..8b5c98b77a5 100644 --- a/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.Ui5ManifestBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:50.6324763\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:46.1498160\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { @@ -1954,11 +1954,11 @@ "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.TechnicalAttributesEntityArray.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsArrayOfKeywords.cs", - "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTa_._RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.RepresentsUniqueIdOfTheSite.cs", "Ui5ManifestSchema.JsonSchemaForSapAppNamespace.RepresentsCrossNavigationForInboundAndOutboundTargets.RepresentsScopesOfASite.cs", @@ -1993,15 +1993,15 @@ "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.I18nEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArt_._TechnicalAttributesEntityArray.TechnicalAttributesEntity.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtif_._TechnicalAttributesEntityArray.TechnicalAttributesEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.TechnicalAttributesEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.TechnicalAttributesEntityArray.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindTheArtifact.cs", - "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsArrayOfKeywordsUsedToFindThe_._TechnicalAttributesEntityArray.TechnicalAttributesEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapArtifactNamespace.RepresentsMandatorySemanticVersionOfTheArtifact.cs", @@ -2182,16 +2182,16 @@ "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.ConfigurationEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAt_._ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttri_._ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttribu_._ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttribu_._ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ActionsStripItemArray.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ActionsStripItemArray.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ActionsStripItemArray.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheNumberOfTheItemsInOnePage.cs", + "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.RepresentsTheTotalCountOfTheItemsInAllPages.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalDescribesThePaginator.cs", "Ui5ManifestSchema.JsonSchemaForSapCardNamespace.RepresentCardFooterAttributes.ExperimentalVisibilityOfTheFooter.JsonSchema.cs", @@ -2230,6 +2230,7 @@ "Ui5ManifestSchema.JsonSchemaForSapCloudNamespace.cs", "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.SettingsForTheContextAnalysisFeaturesOfSapCoPilot.JsonSchema.cs", @@ -2254,7 +2255,6 @@ "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.VersionEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.VersionEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace.cs", - "Ui5ManifestSchema.JsonSchemaForSapCopilotNamespace_._tingsForTheContextAnalysisFeaturesOfSapCoPilot.AllowAddingObjectsFromAppScreenToCollectionEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.ArcheTypeEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.ArcheTypeEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapFioriNamespace.ArcheTypeEntity.cs", @@ -2401,13 +2401,14 @@ "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreAnalyticalChartSettings.cs", - "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBa_._DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarCo_._DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfigura_._DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConf_._DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfigu_._DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.FlagToExcludeValuesFromTheDatePicker.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.RepresentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.UseDateRangeEntity.cs", @@ -2437,7 +2438,6 @@ "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.VersionEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.VersionEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace.cs", - "Ui5ManifestSchema.JsonSchemaForSapOvpNamespace_._resentsTheObjectToStoreFilterBarConfiguration.DateSettingsEntity.RepresentsTheFilterFieldDefinitionForEachField.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.ContentitemArray.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.ContentitemArray.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.ContentitemArray.cs", @@ -2452,12 +2452,12 @@ "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.JsonStringArray.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.JsonStringArray.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindTheP_._TechnicalAttributesEntityArray.TechnicalAttributesEntity.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePack_._TechnicalAttributesEntityArray.TechnicalAttributesEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.TechnicalAttributesEntity.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.TechnicalAttributesEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.TechnicalAttributesEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.TechnicalAttributesEntityArray.cs", "Ui5ManifestSchema.JsonSchemaForSapPackageNamespace.RepresentsArrayOfKeywordsUsedToFindThePackage.cs", @@ -2536,14 +2536,14 @@ "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.AllOf1Entity.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDe_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensi_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndD_._I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndD_._RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDe_._I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDe_._RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDepe_._RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDepen_._RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensiti_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesA_._RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDepend_._I18nEntity.RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDepend_._RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDepende_._I18nEntity.RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDepende_._RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependenc_._RequiredBundleName.RepresentsTerminologiesWithAdditionalPropertiesFiles.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependenci_._RequiredBundleUrl.RepresentsTerminologiesWithAdditionalPropertiesFiles.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ComponentUsagesEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ComponentUsagesEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ComponentUsagesEntity.cs", @@ -2561,9 +2561,6 @@ "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ModelsEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.ModelsEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Repres_._I18nEntity.RequiredBundleName.EnhanceWithSettingArray.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Represe_._I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Represent_._I18nEntity.RequiredBundleName.EnhanceWithSettingArray.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfTheServices.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfTheServices.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsAListOfTheServices.cs", @@ -2579,15 +2576,21 @@ "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheStaticConfigurationForComponents.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheStaticConfigurationForComponents.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsTheStaticConfigurationForComponents.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsU_._I18nEntity.RequiredBundleName.EnhanceWithSettingArray.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5L_._I18nEntity.RequiredBundleName.EnhanceWithSettingArray.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5Li_._I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.I18nEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi5LibrarySpecificProperties.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.Represents_._I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.Mutable.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RepresentsUi_._I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.cs", @@ -2610,14 +2613,11 @@ "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.VersionEntity.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.VersionEntity.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._SpecificProperties.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._esentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._ntsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleUrl.JsonSchema.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._pecificProperties.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._sentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.Mutable.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._tsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.JsonSchema.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._brarySpecificProperties.I18nEntity.RequiredBundleUrl.EnhanceWithSettingArray.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._rarySpecificProperties.I18nEntity.RequiredBundleName.EnhanceWithSettingArray.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.RequiredContentDensitiesAndDependencies_._resentsUi5LibrarySpecificProperties.I18nEntity.RequiredBundleName.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace.cs", - "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace_._tentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.cs", + "Ui5ManifestSchema.JsonSchemaForSapUi5Namespace_._edContentDensitiesAndDependencies.RequiredAppVariantIdAndLayerAndVersionArray.RequiredAppVariantIdAndLayerAndVersion.cs", "Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.JsonSchema.cs", "Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.Mutable.cs", "Ui5ManifestSchema.JsonSchemaForSapUiGenericAppNamespace.PagesEntity.JsonSchema.cs", @@ -2989,6 +2989,7 @@ "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredName.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.JsonSchema.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.Mutable.cs", + "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.JsonSchema.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.Mutable.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredTypeAndUsage.cs", @@ -2997,7 +2998,6 @@ "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity.cs", - "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.SSEntity_._Of1Entity.AllOf1Entity.RequiredTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.JsonSchema.cs", "Ui5ManifestSchema.Routing.RepresentsTheDefinitionOfTargets.cs", "Ui5ManifestSchema.Routing.RoutesEntity.JsonSchema.cs", "Ui5ManifestSchema.Routing.RoutesEntity.Mutable.cs", @@ -3011,8 +3011,8 @@ "Ui5ManifestSchema.Routing.cs", "Ui5ManifestSchema.RoutingFlexEnabled.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.Mutable.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAn_._AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.JsonSchema.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTa_._AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.Mutable.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.JsonSchema.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.Mutable.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.IndicatesWhetherTheViewsInRoutingAreLoadedAsyncly.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.AllOf0Entity.Mutable.cs", @@ -3025,9 +3025,8 @@ "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefaultPropertiesDefinedForRouteAndTarget.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.Mutable.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEn_._AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.JsonSchema.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEnt_._AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.Mutable.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntit_._AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.Mutable.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEnt_._OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntit_._AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.Mutable.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf0Entity.JsonSchema.cs", @@ -3040,6 +3039,7 @@ "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.Mutable.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.Mutable.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndName.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.Mutable.cs", @@ -3049,10 +3049,10 @@ "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.Mutable.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.OneOf1Entity.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SS_._AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.JsonSchema.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SS_._OneOf1Entity.AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity_._AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.JsonSchema.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity_._ity.AllOf1Entity.RequiredIdAndName.RepresentsTheTypeOfTheTypeViewOrComponent.Mutable.cs", + "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.SSEntity_._y.AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.Mutable.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets.cs", - "Ui5ManifestSchema.RoutingFlexEnabled.RepresentsTheDefinitionOfTargets_._OneOf1Entity.AllOf1Entity.RequiredIdAndTypeAndUsage.RepresentsTheTypeOfTheTypeComponent.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.JsonSchema.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.Mutable.cs", "Ui5ManifestSchema.RoutingFlexEnabled.RoutesEntity.OneOf1Entity.JsonSchema.cs", diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonNumber.cs index a7b6abe9ac2..2497246fce5 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonNumber.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonObject.cs index 8698e3bd37b..e568281cc8d 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonString.cs index 7ef6433835e..454e0971621 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildConfiguration.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildConfiguration.cs index 398331b74f2..d1dd200cfca 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildConfiguration.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildConfiguration.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BuildConfiguration Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildTargetType.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildTargetType.cs index eb1ecc43f13..3951db13cf1 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildTargetType.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.BuildTargetType.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BuildTargetType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DescriptorVersionNumber.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DescriptorVersionNumber.cs index c54d6862c58..809d19d86f6 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DescriptorVersionNumber.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DescriptorVersionNumber.cs @@ -410,6 +410,12 @@ private void CheckValidInstance() public DescriptorVersionNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DisableEnginePluginsByDefaultEntity.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DisableEnginePluginsByDefaultEntity.cs index b6f1a8a3301..6247a4edc40 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DisableEnginePluginsByDefaultEntity.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.DisableEnginePluginsByDefaultEntity.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public DisableEnginePluginsByDefaultEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.EngineAssociationEntity.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.EngineAssociationEntity.cs index d8f85331679..32063340022 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.EngineAssociationEntity.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.EngineAssociationEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public EngineAssociationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.IndicatesIfThisProjectIsAnEnterpriseProject.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.IndicatesIfThisProjectIsAnEnterpriseProject.cs index 91365e7b8de..33c5c77900d 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.IndicatesIfThisProjectIsAnEnterpriseProject.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.IndicatesIfThisProjectIsAnEnterpriseProject.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public IndicatesIfThisProjectIsAnEnterpriseProject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.JsonStringArray.cs index e0d35712297..13389711597 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.JsonStringArray.cs @@ -26,11 +26,13 @@ public readonly partial struct UnrealEngineUprojectSchema public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildConfigurationArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildConfigurationArray.cs index cff22c8312d..f7a3d65ca7b 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildConfigurationArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildConfigurationArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ModuleDescriptor public readonly partial struct BuildConfigurationArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public BuildConfigurationArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildTargetTypeArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildTargetTypeArray.cs index c2b7976bae9..ececd74f9a4 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildTargetTypeArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.BuildTargetTypeArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ModuleDescriptor public readonly partial struct BuildTargetTypeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public BuildTargetTypeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.HasExplicitPlatformsEntity.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.HasExplicitPlatformsEntity.cs index 11cdbde2daf..f00b2b4846d 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.HasExplicitPlatformsEntity.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.HasExplicitPlatformsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public HasExplicitPlatformsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.JsonStringArray.cs index 1a88cd2f14d..b3644895367 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ModuleDescriptor public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfAlloArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfAlloArray.cs index 80eada37fd1..ea1951ae23e 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfAlloArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfAlloArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ModuleDescriptor public readonly partial struct ListOfAlloArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfAlloArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisaArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisaArray.cs index 80312dae5bc..0578a0dbffc 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisaArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisaArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ModuleDescriptor public readonly partial struct ListOfDisaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfDisaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisalloweArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisalloweArray.cs index d4af39b4f3e..bcc5285c9b8 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisalloweArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisalloweArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ModuleDescriptor public readonly partial struct ListOfDisalloweArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfDisalloweArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisallowedTaArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisallowedTaArray.cs index 53a72496c50..812e8bf2c5f 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisallowedTaArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.ListOfDisallowedTaArray.cs @@ -28,11 +28,13 @@ public readonly partial struct ModuleDescriptor public readonly partial struct ListOfDisallowedTaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfDisallowedTaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.LoadingPhaseEntity.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.LoadingPhaseEntity.cs index 19966922008..7efeb92bbbe 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.LoadingPhaseEntity.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.LoadingPhaseEntity.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public LoadingPhaseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.Mutable.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.Mutable.cs index e41545eade5..7a8d3c352bf 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.Mutable.cs @@ -1394,6 +1394,36 @@ public bool RemoveType() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HasExplicitPlatformsUtf8, out IJsonDocument? _, out int _)) + { + SetHasExplicitPlatforms(Corvus.UnrealEngineUprojectBenchmark.Current.UnrealEngineUprojectSchema.ModuleDescriptor.HasExplicitPlatformsEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.UsageTypeOfModule.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.UsageTypeOfModule.cs index 9bfef38788d..a4738728e4f 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.UsageTypeOfModule.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.UsageTypeOfModule.cs @@ -320,6 +320,12 @@ private void CheckValidInstance() public UsageTypeOfModule Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.cs index 872357d96bb..f207b9e56db 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptor.cs @@ -617,6 +617,12 @@ private void CheckValidInstance() public ModuleDescriptor Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptorArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptorArray.cs index 2e2ad3c3697..d67b5ce9666 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptorArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.ModuleDescriptorArray.cs @@ -26,11 +26,13 @@ public readonly partial struct UnrealEngineUprojectSchema public readonly partial struct ModuleDescriptorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public ModuleDescriptorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.Mutable.cs index a3607e1b18c..c1ca51b839a 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.Mutable.cs @@ -1086,6 +1086,46 @@ public bool RemoveTargetPlatforms() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.DisableEnginePluginsByDefaultUtf8, out IJsonDocument? _, out int _)) + { + SetDisableEnginePluginsByDefault(Corvus.UnrealEngineUprojectBenchmark.Current.UnrealEngineUprojectSchema.DisableEnginePluginsByDefaultEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.FileVersionUtf8, out IJsonDocument? _, out int _)) + { + SetFileVersion(Corvus.UnrealEngineUprojectBenchmark.Current.UnrealEngineUprojectSchema.DescriptorVersionNumber.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.IsEnterpriseProjectUtf8, out IJsonDocument? _, out int _)) + { + SetIsEnterpriseProject(Corvus.UnrealEngineUprojectBenchmark.Current.UnrealEngineUprojectSchema.IndicatesIfThisProjectIsAnEnterpriseProject.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildConfigurationArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildConfigurationArray.cs index 7e877b7033e..e6fdc2533a1 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildConfigurationArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildConfigurationArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginReferenceDescriptor public readonly partial struct BuildConfigurationArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public BuildConfigurationArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildTargetTypeArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildTargetTypeArray.cs index af6e383ce09..c877be84e70 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildTargetTypeArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.BuildTargetTypeArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginReferenceDescriptor public readonly partial struct BuildTargetTypeArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public BuildTargetTypeArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.HasExplicitPlatformsEntity.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.HasExplicitPlatformsEntity.cs index 2e14ef7c08a..cadd4c6480e 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.HasExplicitPlatformsEntity.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.HasExplicitPlatformsEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public HasExplicitPlatformsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.JsonStringArray.cs index ed6c03fac5c..4b8b4ca5ca7 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.JsonStringArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginReferenceDescriptor public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisaArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisaArray.cs index 6259c295388..56e3c0ece1a 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisaArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisaArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginReferenceDescriptor public readonly partial struct ListOfDisaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfDisaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisalloweArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisalloweArray.cs index 10c4fc33ddd..546f57bd933 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisalloweArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisalloweArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginReferenceDescriptor public readonly partial struct ListOfDisalloweArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfDisalloweArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisallowedTaArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisallowedTaArray.cs index 327722fc003..5acb8ac0d71 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisallowedTaArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.ListOfDisallowedTaArray.cs @@ -28,11 +28,13 @@ public readonly partial struct PluginReferenceDescriptor public readonly partial struct ListOfDisallowedTaArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -82,6 +84,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -295,6 +312,12 @@ private void CheckValidInstance() public ListOfDisallowedTaArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.Mutable.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.Mutable.cs index 2186077dc5f..bd528d1440e 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.Mutable.cs @@ -1198,6 +1198,46 @@ public bool RemoveTargetDenyList() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.EnabledUtf8, out IJsonDocument? _, out int _)) + { + SetEnabled(Corvus.UnrealEngineUprojectBenchmark.Current.UnrealEngineUprojectSchema.PluginReferenceDescriptor.WhetherItShouldBeEnabledByDefault.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.HasExplicitPlatformsUtf8, out IJsonDocument? _, out int _)) + { + SetHasExplicitPlatforms(Corvus.UnrealEngineUprojectBenchmark.Current.UnrealEngineUprojectSchema.PluginReferenceDescriptor.HasExplicitPlatformsEntity.DefaultInstance); + } + + if (!_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.OptionalUtf8, out IJsonDocument? _, out int _)) + { + SetOptional(Corvus.UnrealEngineUprojectBenchmark.Current.UnrealEngineUprojectSchema.PluginReferenceDescriptor.OptionalEntity.DefaultInstance); + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.OptionalEntity.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.OptionalEntity.cs index d3a602bde86..c6af666c2b5 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.OptionalEntity.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.OptionalEntity.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public OptionalEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.WhetherItShouldBeEnabledByDefault.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.WhetherItShouldBeEnabledByDefault.cs index edb13817a85..36b158f39f6 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.WhetherItShouldBeEnabledByDefault.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.WhetherItShouldBeEnabledByDefault.cs @@ -316,6 +316,12 @@ private void CheckValidInstance() public WhetherItShouldBeEnabledByDefault Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.cs index b178db1bec8..61acf998b95 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptor.cs @@ -602,6 +602,12 @@ private void CheckValidInstance() public PluginReferenceDescriptor Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptorArray.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptorArray.cs index 07f3bd1309c..8a21f065939 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptorArray.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.PluginReferenceDescriptorArray.cs @@ -26,11 +26,13 @@ public readonly partial struct UnrealEngineUprojectSchema public readonly partial struct PluginReferenceDescriptorArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public PluginReferenceDescriptorArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.cs b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.cs index 329db3d40b3..fd1216ad40d 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.cs +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/UnrealEngineUprojectSchema.cs @@ -526,6 +526,12 @@ private void CheckValidInstance() public UnrealEngineUprojectSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/corvusjson-jsonschema.lock index 11830271053..57179c8d63b 100644 --- a/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.UnrealEngineUprojectBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:51.5241263\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:48.8026759\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonBoolean.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonBoolean.cs index 220ac769616..db8fb2d5295 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonBoolean.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonBoolean.cs @@ -303,6 +303,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonNumber.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonNumber.cs index 4a3032d7013..6dca486868a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonNumber.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonNumber.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonNumber Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonObject.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonObject.cs index fb2b889a44b..8da56efc203 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonObject.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonObject.cs @@ -341,6 +341,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonString.cs index 012f338760f..976820c67bb 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index d3874709ee1..73218b766e5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index 03c535fcae5..c3abe91029a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs index c427f10359a..09562e998b3 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public DestinationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs index ef9aa52d451..be372e2fea5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs @@ -323,6 +323,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index c3492dd3bfd..d817e33f64e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs index 99b5155efa0..90ec1efcfe2 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs index f224f0c83c2..217bfa3e693 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs index 8c5e7cf979a..5d6db542781 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs @@ -257,6 +257,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.AList _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index effc53972ff..f7b27e757a1 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs index 8e5a6e6f7b0..4be5583d09f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs index 6ceca38d2c9..936c0eb3849 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs index 936117dadc1..786becae9bd 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HasEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs index 55fe13e6660..7b48fab38a9 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDestinationAndSourceEntity public readonly partial struct HasEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public HasEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs index 102e3d7b695..784b9281529 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs @@ -323,6 +323,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs index c3885fe934a..7453c700490 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs index 4fcf5177ef6..ba519e46a17 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs index 1f0d2281381..6712e38c424 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs @@ -257,6 +257,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.AList _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs index 5ad4cddb2a9..1eb4ca6785d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs index 93b23f1d7b9..56e1b44eaf8 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs index 931cceff6e5..ee351254957 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public MissingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs index 1972418cd52..fa1f4211bb0 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDestinationAndSourceEntity public readonly partial struct MissingEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public MissingEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Mutable.cs index c152af8db2c..1b12c359b01 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Mutable.cs @@ -455,6 +455,31 @@ public void SetSourceValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.SourceEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.SourceEntity.cs index 63583b20c5a..ae28926785d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.SourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.SourceEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public SourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.cs index 8b80ae59078..c8173d6527f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public RequiredDestinationAndSourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index 0d472f388cf..3e4f97ce11a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index 626390d9fe1..fe65e38d2d9 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.cs index 2194c42116b..05678b38b18 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AListOfRewriteDefiniRequiredDestinArray.cs @@ -26,11 +26,13 @@ public readonly partial struct VercelSchema public readonly partial struct AListOfRewriteDefiniRequiredDestinArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public AListOfRewriteDefiniRequiredDestinArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.Type1Entity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.Type1Entity.cs index 984c1dbc647..699ff9e17ac 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.Type1Entity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.Type1Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public Type1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.cs index 401636ed289..47278d83218 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.OneOf1Array.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public OneOf1Array Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.cs index 131c71e3733..3b5e43c07ce 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.AliasEntity.cs @@ -369,6 +369,12 @@ private void CheckValidInstance() public AliasEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildCommandEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildCommandEntity.cs index a56be9cd666..47bed629138 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildCommandEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildCommandEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public BuildCommandEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.Entity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.Entity.cs index 7d1f877fe54..fe9e61bb7c4 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.Entity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.Entity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.cs index 7d9c953479d..f7973dafcfd 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.EnvEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public EnvEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.Mutable.cs index d99b42a0f7a..42aad35e4e4 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.Mutable.cs @@ -241,6 +241,31 @@ public bool RemoveEnv() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.cs index b9bdbb4348d..2e22e09cafe 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.BuildEntity.cs @@ -292,6 +292,12 @@ private void CheckValidInstance() public BuildEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.DevCommandEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.DevCommandEntity.cs index 28a81ed0fc6..0b1d52a23ea 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.DevCommandEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.DevCommandEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public DevCommandEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.Entity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.Entity.cs index 37ea14f333f..aa660de902b 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.Entity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.Entity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.cs index 302cd2ff74c..a3ed34c5b29 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.EnvEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public EnvEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FrameworkEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FrameworkEntity.cs index 164b82c4ffc..5cae96e2889 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FrameworkEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FrameworkEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public FrameworkEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.ExcludeFilesEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.ExcludeFilesEntity.cs index 598e2e2554d..ab8672f579e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.ExcludeFilesEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.ExcludeFilesEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public ExcludeFilesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.IncludeFilesEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.IncludeFilesEntity.cs index ad7539ac5ad..3aa2a4cd549 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.IncludeFilesEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.IncludeFilesEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public IncludeFilesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MaxDurationEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MaxDurationEntity.cs index 14547472e76..edec49c5aea 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MaxDurationEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MaxDurationEntity.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public MaxDurationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MemoryEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MemoryEntity.cs index d688cd2627b..e7a2e9f614b 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MemoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.MemoryEntity.cs @@ -406,6 +406,12 @@ private void CheckValidInstance() public MemoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.Mutable.cs index f2f4d6e27fe..77988c0840f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.Mutable.cs @@ -471,6 +471,31 @@ public bool RemoveRuntime() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.TheNpmPackageNameOfARuntimeIncludingItsVersion.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.TheNpmPackageNameOfARuntimeIncludingItsVersion.cs index dcb67e1d44c..8efb238025b 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.TheNpmPackageNameOfARuntimeIncludingItsVersion.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.TheNpmPackageNameOfARuntimeIncludingItsVersion.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public TheNpmPackageNameOfARuntimeIncludingItsVersion Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.cs index 05fe6ea8acb..3514d729e4e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.Type1256Entity.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public Type1256Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.cs index 799c1128e24..9bd1df5d935 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.FunctionsEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public FunctionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.OneOf1Entity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.OneOf1Entity.cs index 0e1dca660c9..0956bf9402d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.OneOf1Entity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.OneOf1Entity.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public OneOf1Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.cs index 02880fc4e1a..811f0660805 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.DeploymentEnabledEntity.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public DeploymentEnabledEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.Mutable.cs index ceb7fc13e7c..a6c90621d8a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.Mutable.cs @@ -314,6 +314,31 @@ public bool RemoveDeploymentEnabled() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.cs index 3d9e8100654..984acac9e12 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GitEntity.cs @@ -360,6 +360,12 @@ private void CheckValidInstance() public GitEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.Mutable.cs index 586499fece7..4b49b8aa6f2 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.Mutable.cs @@ -476,6 +476,31 @@ public bool RemoveSilent() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.cs index 37d84fdcd54..2783c33391d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.GithubEntity.cs @@ -423,6 +423,12 @@ private void CheckValidInstance() public GithubEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.IgnoreCommandEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.IgnoreCommandEntity.cs index 8fe87278e74..35c9224b104 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.IgnoreCommandEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.IgnoreCommandEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public IgnoreCommandEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.InstallCommandEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.InstallCommandEntity.cs index 74077d7d1de..357136231c7 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.InstallCommandEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.InstallCommandEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public InstallCommandEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.Mutable.cs index 7fea44ac7aa..9a2b818afd1 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.Mutable.cs @@ -2495,6 +2495,55 @@ public bool RemoveWildcard() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.BuildValueUtf8, out Corvus.VercelBenchmark.Current.VercelSchema.BuildEntity.Mutable __corvusBuildValue)) + { + __corvusBuildValue.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GitUtf8, out Corvus.VercelBenchmark.Current.VercelSchema.GitEntity.Mutable __corvusGit)) + { + __corvusGit.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.GithubUtf8, out Corvus.VercelBenchmark.Current.VercelSchema.GithubEntity.Mutable __corvusGithub)) + { + __corvusGithub.ApplyDefaults(); + _documentVersion = _parent.Version; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.ImagesUtf8, out Corvus.VercelBenchmark.Current.VercelSchema.RequiredSizes.Mutable __corvusImages)) + { + __corvusImages.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.OutputDirectoryEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.OutputDirectoryEntity.cs index dad91b869c3..fa648c884f5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.OutputDirectoryEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.OutputDirectoryEntity.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public OutputDirectoryEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.RegionsEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.RegionsEntity.cs index 7233175f7d9..545eaa70f6e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.RegionsEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.RegionsEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public RegionsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.cs index e0bc20114ba..9c27687958f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RegionsEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct VercelSchema public readonly partial struct RegionsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RegionsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index bc3bee5ca1a..9d91fb0b833 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index 034c7ee14a3..dbc85e2f679 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs index bee337f2a6b..f26d202893a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public DestinationEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs index 0827a3d7841..6e51fab9cfa 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs @@ -323,6 +323,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index a57484f230d..ebeedfa1503 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs index 3f042593c8e..72e0dab92d1 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs index 4387b2e973f..0cb573f11f6 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs index 62917802385..ba491693373 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs @@ -257,6 +257,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Requi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index 719a72baebc..28eebb5114a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs index 63cd8e344f7..1d47ffc49e9 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs index a71fce44cd5..64335e02c90 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs index 569cfa7a998..667396e2d90 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HasEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs index 368330e8eaa..26fc03842be 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDestinationAndSourceEntity public readonly partial struct HasEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public HasEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs index 771329d2b58..848f31cdf78 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs @@ -323,6 +323,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs index 9625d5ec949..db61e186588 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs index dbce26b9a5c..bc7d66d1792 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs index eb2a1a95d8c..47000839193 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs @@ -257,6 +257,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Requi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs index 28e195768fa..fc658c4a372 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs index ccf17592a09..e578c76369c 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs index 768a4089a5e..914eaa63ea0 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public MissingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs index 37452eb4bfa..db43ff275b8 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredDestinationAndSourceEntity public readonly partial struct MissingEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public MissingEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Mutable.cs index 11fb5f3af5b..613d6f19ac5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Mutable.cs @@ -582,6 +582,31 @@ public bool RemoveStatusCode() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.SourceEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.SourceEntity.cs index ca9324a956d..fe374489f0b 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.SourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.SourceEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public SourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.StatusCodeEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.StatusCodeEntity.cs index f31411b9819..31d96385b52 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.StatusCodeEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.StatusCodeEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public StatusCodeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.cs index 6080efddaf6..f1db9e520c3 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public RequiredDestinationAndSourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index c044fe8c0b1..50d14f2e08e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index a159ea2608d..8b0398e0d3e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.cs index a8d7b23204a..77cb7131c37 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDestinationAndSourceEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct VercelSchema public readonly partial struct RequiredDestinationAndSourceEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RequiredDestinationAndSourceEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.DomainEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.DomainEntity.cs index 881f1d3e3dc..8cf5a3ca841 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.DomainEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.DomainEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DomainEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.Mutable.cs index 6a6cd7a6aec..b327806b6e4 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.Mutable.cs @@ -245,6 +245,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Requi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.ValueEntity.cs index 9e405b42e7a..22c05af6c51 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.ValueEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.cs index 21214604a49..864a4ed5ae5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.RequiredDomainAndValue.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public RequiredDomainAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.cs index 633775e4ef5..bc26e08b44b 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredDomainAndValueArray.cs @@ -21,11 +21,13 @@ public readonly partial struct VercelSchema public readonly partial struct RequiredDomainAndValueArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public RequiredDomainAndValueArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs index 80bf70584e2..b9ee7c710e6 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs @@ -323,6 +323,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index 6f813ee5cc3..aa3a23e856e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs index 0db92bae88e..4fa9031633b 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs index d17f855666e..8dd60aaaa30 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs index 9afdeceeb23..a7c92b13ac4 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs @@ -257,6 +257,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Requi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index b6437d77e75..71bb53a042e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs index 08ace7b6bc5..96272046c8e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs index 6e33bccf84e..7393237ccb1 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.cs index 307c5266070..ff30c754d00 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public HasEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.cs index 0a1af2a1b06..87596d5c5df 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredHeadersAndSourceEntity public readonly partial struct HasEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public HasEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs index 8f8ab500a6d..b93006a3946 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs @@ -323,6 +323,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index ace52997152..955aab66b45 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs index 32881c40aab..f5bf29c4086 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs index beb5b19f143..0703d08f201 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs index d7c35ab33ce..836481fd9d5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs @@ -257,6 +257,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Requi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index dfd945b9562..bf38277a25d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -333,6 +333,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs index 3edd230d470..c6384f8e16e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs index 38c1d38e2fc..cc00b270974 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.cs index 6235dec39f5..ef7723a33ff 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public MissingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.cs index 43c1110ef3a..219dc74afd5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredHeadersAndSourceEntity public readonly partial struct MissingEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public MissingEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.Mutable.cs index 656a39ed703..91f0bbf4d49 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.Mutable.cs @@ -489,6 +489,31 @@ public void SetSourceValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.KeyEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.KeyEntity.cs index 500cffd2ac4..c00ad7bcb2b 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.KeyEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.KeyEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public KeyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs index 924641490ee..0873159852a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.Mutable.cs @@ -249,6 +249,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Requi _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.ValueEntity.cs index f7dd7b8d853..1cb6f900a81 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.ValueEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs index 392ccebdfb4..09d17a6ce26 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.RequiredKeyAndValue.cs @@ -314,6 +314,12 @@ private void CheckValidInstance() public RequiredKeyAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.cs index fdd175e8a6f..8ea916e466d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.cs @@ -30,11 +30,13 @@ public readonly partial struct RequiredHeadersAndSourceEntity public readonly partial struct RequiredKeyAndValueArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -84,6 +86,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -297,6 +314,12 @@ private void CheckValidInstance() public RequiredKeyAndValueArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.SourceEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.SourceEntity.cs index 7a781a08da2..8ed3d8bda3e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.SourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.SourceEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public SourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.cs index c2559fe36f2..461a8c579cb 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.cs @@ -358,6 +358,12 @@ private void CheckValidInstance() public RequiredHeadersAndSourceEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._ay.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._ay.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index ea564b3ee06..ca004620d53 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._ay.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._ay.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._yArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._yArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index 17a5ad36c79..aab800f3f60 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._yArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._yArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -328,6 +328,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.cs index 234c76d201a..4ad0b77e380 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredHeadersAndSourceEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct VercelSchema public readonly partial struct RequiredHeadersAndSourceEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RequiredHeadersAndSourceEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.Mutable.cs index 6f23e089623..a53aa6f80ed 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.Mutable.cs @@ -318,6 +318,31 @@ public void SetSchedule(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Re _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.PathEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.PathEntity.cs index d0886edfed5..aacf7f254c0 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.PathEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.PathEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public PathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.ScheduleEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.ScheduleEntity.cs index 2622b18deae..309b6e78247 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.ScheduleEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.ScheduleEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public ScheduleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.cs index 0355620a31d..b9024d4cdbb 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.RequiredPathAndSchedule.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredPathAndSchedule Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.cs index 34858121818..1af2942310f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredPathAndScheduleArray.cs @@ -26,11 +26,13 @@ public readonly partial struct VercelSchema public readonly partial struct RequiredPathAndScheduleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RequiredPathAndScheduleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentDispositionTypeEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentDispositionTypeEntity.cs index 28ca13c851b..b7f4c69f1d2 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentDispositionTypeEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentDispositionTypeEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public ContentDispositionTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentSecurityPolicyEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentSecurityPolicyEntity.cs index 7a6883a5458..61a2a639bc5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentSecurityPolicyEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.ContentSecurityPolicyEntity.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public ContentSecurityPolicyEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.DomainsEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.DomainsEntity.cs index aa33a88b375..c89663471a0 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.DomainsEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.DomainsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public DomainsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.cs index 67a4117b9da..42dd1877dcc 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.DomainsEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct RequiredSizes public readonly partial struct DomainsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public DomainsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.FormatsEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.FormatsEntity.cs index 2a69c5040a6..8cb5ef38c30 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.FormatsEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.FormatsEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public FormatsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.cs index 99524a20933..cb9f30c8f3a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.FormatsEntityArray.cs @@ -23,11 +23,13 @@ public readonly partial struct RequiredSizes public readonly partial struct FormatsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public FormatsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.JsonNumberArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.JsonNumberArray.cs index 198eb9b7f85..b988b3aad72 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.JsonNumberArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.JsonNumberArray.cs @@ -23,11 +23,13 @@ public readonly partial struct RequiredSizes public readonly partial struct JsonNumberArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -105,6 +107,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -318,6 +335,12 @@ private void CheckValidInstance() public JsonNumberArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.MinimumCacheTtlEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.MinimumCacheTtlEntity.cs index fd262c716fd..1cd043bf446 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.MinimumCacheTtlEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.MinimumCacheTtlEntity.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public MinimumCacheTtlEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.Mutable.cs index 5ce7122d127..fd2598007d8 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.Mutable.cs @@ -760,6 +760,31 @@ public void SetSizes(in Corvus.VercelBenchmark.Current.VercelSchema.Re _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.HostnameEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.HostnameEntity.cs index 6099a5faa69..0941f55452c 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.HostnameEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.HostnameEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public HostnameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.Mutable.cs index 8bf12248bc4..8dcaa581d9c 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.Mutable.cs @@ -378,6 +378,31 @@ public bool RemoveProtocol() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PathnameEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PathnameEntity.cs index 79432b12ada..6847a6fb547 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PathnameEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PathnameEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public PathnameEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PortEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PortEntity.cs index 6a1ccc07cbc..c7a8682bb7f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PortEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.PortEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public PortEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.ProtocolEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.ProtocolEntity.cs index ce04b70b365..c3aac7e7eba 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.ProtocolEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.ProtocolEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public ProtocolEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.cs index e48bbacd474..f93c5aa09ff 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.RequiredHostname.cs @@ -339,6 +339,12 @@ private void CheckValidInstance() public RequiredHostname Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.cs index 452ef57300b..1eae4d31054 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.RequiredHostnameArray.cs @@ -23,11 +23,13 @@ public readonly partial struct RequiredSizes public readonly partial struct RequiredHostnameArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public RequiredHostnameArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.cs index 98bdb21b1a4..7e339375522 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredSizes.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public RequiredSizes Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.Mutable.cs index dd57ef74c8d..2c34f0309ce 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.Mutable.cs @@ -364,6 +364,31 @@ public void SetUse(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Require _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.SrcEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.SrcEntity.cs index 5fc3a2ee99a..67b00b4bb33 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.SrcEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.SrcEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public SrcEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.UseEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.UseEntity.cs index 02ef01bc07a..4d223e1f3b6 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.UseEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.UseEntity.cs @@ -322,6 +322,12 @@ private void CheckValidInstance() public UseEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.cs index 84e3751b7d6..bb70bd884bf 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.RequiredUse.cs @@ -334,6 +334,12 @@ private void CheckValidInstance() public RequiredUse Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.cs index 77155a8393d..de449734a1c 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RequiredUseArray.cs @@ -26,11 +26,13 @@ public readonly partial struct VercelSchema public readonly partial struct RequiredUseArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RequiredUseArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.HandleEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.HandleEntity.cs index 15a5799532c..2719badcdc8 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.HandleEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.HandleEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public HandleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.Mutable.cs index 4c948f64ce8..3cbf4bbfd2f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.Mutable.cs @@ -195,6 +195,31 @@ public void SetHandle(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Rout _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.cs index 4185db1e670..aadca74d4e2 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredHandle.cs @@ -291,6 +291,12 @@ private void CheckValidInstance() public RequiredHandle Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.DestEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.DestEntity.cs index 74d280ae0f2..7ae108ae7e7 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.DestEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.DestEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public DestEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs index f7b00f02a2d..fb1b7572dde 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs @@ -325,6 +325,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index 193faaebf33..4bd991b5f0d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index 364f29a5814..50602d691ca 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs index 63fc8ea7ee9..ceb8d6bd27e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.cs index 0d5d7a8dd89..519578f9994 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredKeyAndType.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs index 289bb4ac004..80cd59945f5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs @@ -259,6 +259,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Route _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index 453fc53b583..97257f409e0 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs index b59130fa72f..340e12c0c36 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.cs index 5188b507433..a1df180df7e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.RequiredTypeAndValue.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.cs index b578484301b..25c8f975279 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.HasEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public HasEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.cs index f932d355f88..3079fc3144a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HasEntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct RequiredSrc public readonly partial struct HasEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public HasEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.Type1256Entity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.Type1256Entity.cs index e273bac64a4..47d693dbdab 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.Type1256Entity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.Type1256Entity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public Type1256Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.cs index b64402998d2..9df0df3c5da 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.HeadersEntity.cs @@ -398,6 +398,12 @@ private void CheckValidInstance() public HeadersEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.JsonStringArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.JsonStringArray.cs index b40bf563d30..6ea045097d4 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.JsonStringArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.JsonStringArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredSrc public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.CookieEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.CookieEntity.cs index 02d1cf3c739..2d492d0664e 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.CookieEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.CookieEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public CookieEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.DefaultEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.DefaultEntity.cs index da306bb38c7..cc89da235e7 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.DefaultEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.DefaultEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public DefaultEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.Mutable.cs index c4af90bcf45..3707431d558 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.Mutable.cs @@ -486,6 +486,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.PathEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.PathEntity.cs index 6b305a0d1cd..324f1e972a7 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.PathEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.PathEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public PathEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.Type1256Entity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.Type1256Entity.cs index bc693b86a89..bafad1f30b2 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.Type1256Entity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.Type1256Entity.cs @@ -323,6 +323,12 @@ private void CheckValidInstance() public Type1256Entity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.cs index bf7585a42a3..8f6a3b04ae6 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.RedirectEntity.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public RedirectEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.ValueEntity.cs index 39604ca367c..cc58aeac7fe 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.ValueEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.cs index 4f8f1fc523c..9a1e875877a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.cs @@ -352,6 +352,12 @@ private void CheckValidInstance() public LocaleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.MethodsEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.MethodsEntity.cs index 9c3fd6bf65f..2b668ec3a08 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.MethodsEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.MethodsEntity.cs @@ -321,6 +321,12 @@ private void CheckValidInstance() public MethodsEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.cs index 61cf0e63ccc..fc8f004a381 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MethodsEntityArray.cs @@ -27,11 +27,13 @@ public readonly partial struct RequiredSrc public readonly partial struct MethodsEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -81,6 +83,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -294,6 +311,12 @@ private void CheckValidInstance() public MethodsEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs index ca88e3360ce..c17778d7320 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs @@ -325,6 +325,31 @@ public bool RemoveValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs index b0c29a8836e..46f2eae436f 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheNameOfTheElementContainedInTheParticularType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs index 448c83c4907..bbf9bef162a 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs index 533c1ef7d41..194c8ae8c91 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs index b625c503a73..202df2963da 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.cs @@ -345,6 +345,12 @@ private void CheckValidInstance() public RequiredKeyAndType Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs index d26265cda49..4ed421702bc 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.Mutable.cs @@ -259,6 +259,31 @@ public void SetValue(scoped in Corvus.VercelBenchmark.Current.VercelSchema.Route _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs index 3358c4b577a..de881f34f0d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs @@ -335,6 +335,12 @@ private void CheckValidInstance() public TheTypeOfRequestElementToCheck Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs index 337820d6bfa..587fbef3fbc 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.ValueEntity.cs @@ -330,6 +330,12 @@ private void CheckValidInstance() public ValueEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs index c9ce5caccf0..29c46ffedde 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredTypeAndValue.cs @@ -324,6 +324,12 @@ private void CheckValidInstance() public RequiredTypeAndValue Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.cs index 6df41a7af6f..608131a5fc5 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.cs @@ -401,6 +401,12 @@ private void CheckValidInstance() public MissingEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.cs index 1f9a37bb906..c884dc4b0ad 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.cs @@ -32,11 +32,13 @@ public readonly partial struct RequiredSrc public readonly partial struct MissingEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -86,6 +88,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -299,6 +316,12 @@ private void CheckValidInstance() public MissingEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.Mutable.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.Mutable.cs index 37e3eb8cc41..61bb016ace0 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.Mutable.cs @@ -1458,6 +1458,37 @@ public bool RemoveUser() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + + if (_parent.TryGetNamedPropertyValue(_idx, JsonPropertyNames.LocaleUtf8, out Corvus.VercelBenchmark.Current.VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.LocaleEntity.Mutable __corvusLocale)) + { + __corvusLocale.ApplyDefaults(); + _documentVersion = _parent.Version; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.SrcEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.SrcEntity.cs index a0e73184383..53cc8374de8 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.SrcEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.SrcEntity.cs @@ -319,6 +319,12 @@ private void CheckValidInstance() public SrcEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.StatusEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.StatusEntity.cs index 343dbc7afb4..0d28ef5f89d 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.StatusEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.StatusEntity.cs @@ -403,6 +403,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.cs index 3b696e5d0b6..44ad0fdecdd 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.cs @@ -573,6 +573,12 @@ private void CheckValidInstance() public RequiredSrc Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.cs index 0aa9fa0e778..f2292cbcffd 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.RoutesEntity.cs @@ -395,6 +395,12 @@ private void CheckValidInstance() public RoutesEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.cs index 8a9ada33f2c..59cbe083dd4 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.RoutesEntityArray.cs @@ -26,11 +26,13 @@ public readonly partial struct VercelSchema public readonly partial struct RoutesEntityArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -80,6 +82,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -293,6 +310,12 @@ private void CheckValidInstance() public RoutesEntityArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.VersionEntity.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.VersionEntity.cs index 9d3a2cd11be..0af63eff631 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.VersionEntity.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.VersionEntity.cs @@ -397,6 +397,12 @@ private void CheckValidInstance() public VersionEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.cs b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.cs index 6e72632ed77..836c8700759 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.cs +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/VercelSchema.cs @@ -822,6 +822,12 @@ private void CheckValidInstance() public VercelSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/corvusjson-jsonschema.lock index 8c6837ea619..de5902ccc55 100644 --- a/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.VercelBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:52.5876149\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:50.6736377\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { @@ -47,21 +47,16 @@ "JsonString.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.Mutable.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEn_.__RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema1.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEnti_._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.DestinationEntity.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.DestinationEntity.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Ha_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasE_._HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEn_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEnti_._HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEnti_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityA_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.Mutable.cs", @@ -78,14 +73,18 @@ "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.HasEntity_._HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.JsonSchema.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.M_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Mis_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Mis_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Missi_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.Missin_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingE_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.JsonSchema.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs", @@ -104,12 +103,13 @@ "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.SourceEntity.Mutable.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.SourceEntity.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable1.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._issingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._ingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._ntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._ray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity_._ty.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity__._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema1.cs", + "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.RequiredDestinationAndSourceEntity__._ity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable1.cs", "VercelSchema.AListOfRewriteDefiniRequiredDestinArray.cs", "VercelSchema.AliasEntity.JsonSchema.cs", "VercelSchema.AliasEntity.Mutable.cs", @@ -196,21 +196,16 @@ "VercelSchema.RegionsEntityArray.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.Mutable.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceE_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEn_.__RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema1.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEnti_._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntit_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.DestinationEntity.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.DestinationEntity.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.DestinationEntity.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Ha_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasE_._HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEn_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEnti_._HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEnti_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityA_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.Mutable.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.ValueEntity.Mutable.cs", @@ -227,14 +222,18 @@ "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntityArray.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.HasEntity_._HasEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.JsonSchema.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.M_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Mis_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Mis_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Missi_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.Missin_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingE_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.JsonSchema.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.cs", @@ -256,12 +255,13 @@ "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.StatusCodeEntity.Mutable.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.StatusCodeEntity.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._EntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable1.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._issingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._tityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._ingEntityArray.MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._ntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._ray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity_._ty.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity__._RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema1.cs", + "VercelSchema.RequiredDestinationAndSourceEntityArray.RequiredDestinationAndSourceEntity__._ity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable1.cs", "VercelSchema.RequiredDestinationAndSourceEntityArray.cs", "VercelSchema.RequiredDomainAndValueArray.JsonSchema.cs", "VercelSchema.RequiredDomainAndValueArray.Mutable.cs", @@ -277,7 +277,6 @@ "VercelSchema.RequiredDomainAndValueArray.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.Mutable.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityA_._HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.JsonSchema.cs", @@ -291,6 +290,7 @@ "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredKeyAndType.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.Mutable.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.HasEntity.RequiredTypeAndValue.ValueEntity.JsonSchema.cs", @@ -301,16 +301,16 @@ "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.HasEntityArray.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.Has_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.JsonSchema.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.Missin_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingE_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEn_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEnti_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEnti_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.JsonSchema.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityA_._MissingEntity.RequiredTypeAndValue.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.RequiredKeyAndType.ValueEntity.Mutable.cs", @@ -326,6 +326,7 @@ "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.MissingEntity.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntityArray.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.MissingEntity_._MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.JsonSchema.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.RequiredKeyAndValueArray.Mutable.cs", @@ -343,12 +344,11 @@ "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.SourceEntity.Mutable.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.SourceEntity.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._asEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._ay.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._ngEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._ntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._yArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", - "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity__._ity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema1.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._EntityArray.HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._HasEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._singEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", + "VercelSchema.RequiredHeadersAndSourceEntityArray.RequiredHeadersAndSourceEntity_._tyArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", "VercelSchema.RequiredHeadersAndSourceEntityArray.cs", "VercelSchema.RequiredPathAndScheduleArray.JsonSchema.cs", "VercelSchema.RequiredPathAndScheduleArray.Mutable.cs", @@ -501,6 +501,7 @@ "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.Mutable.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.JsonSchema.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.Mutable.cs", + "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.Mutable.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.MissingEntityArray.MissingEntity.RequiredKeyAndType.TheTypeOfRequestElementToCheck.JsonSchema.cs", @@ -530,7 +531,6 @@ "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.StatusEntity.Mutable.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.StatusEntity.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc.cs", - "VercelSchema.RoutesEntityArray.RoutesEntity.RequiredSrc_._singEntityArray.MissingEntity.RequiredKeyAndType.TheNameOfTheElementContainedInTheParticularType.JsonSchema.cs", "VercelSchema.RoutesEntityArray.RoutesEntity.cs", "VercelSchema.RoutesEntityArray.cs", "VercelSchema.VersionEntity.JsonSchema.cs", diff --git a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/JsonString.cs b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/JsonString.cs index 6180f954423..1577031591a 100644 --- a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/JsonString.cs +++ b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/JsonString.cs @@ -315,6 +315,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.Mutable.cs b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.Mutable.cs index f5e88c28772..f4fb7746526 100644 --- a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.Mutable.cs @@ -279,6 +279,31 @@ public bool RemoveIgnoreValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.cs b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.cs index 82e1e234dde..886bb8fb55f 100644 --- a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.cs +++ b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Ignore.cs @@ -361,6 +361,12 @@ private void CheckValidInstance() public Ignore Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Mutable.cs b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Mutable.cs index 212ad22e4e3..e3e97ffcbbc 100644 --- a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Mutable.cs +++ b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.Mutable.cs @@ -294,6 +294,31 @@ public bool RemoveIgnoreValue() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// /// Apply a composed value. /// diff --git a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.cs b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.cs index 3adcab77583..6a4062f743d 100644 --- a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.cs +++ b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/YamllintSchema.cs @@ -381,6 +381,12 @@ private void CheckValidInstance() public YamllintSchema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/corvusjson-jsonschema.lock b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/corvusjson-jsonschema.lock index dccfbdc0977..51315805099 100644 --- a/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/corvusjson-jsonschema.lock +++ b/benchmarks/Corvus.Text.Json.YamllintBenchmarkModels/C/corvusjson-jsonschema.lock @@ -1,6 +1,6 @@ { - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", - "generatedAt": "2026-10-31T09:01:53.3787498\u002B00:00", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", + "generatedAt": "2026-11-02T14:20:53.0928842\u002B00:00", "engine": "V5", "codeGenerationMode": "TypeGeneration", "specification": { diff --git a/docs/CodeGenerator.md b/docs/CodeGenerator.md index 6f4136ced3b..8b140ec6cda 100644 --- a/docs/CodeGenerator.md +++ b/docs/CodeGenerator.md @@ -66,6 +66,7 @@ corvusjson jsonschema [OPTIONS] | `--regexEngine` | `Ecma262` | The engine the generated regular expressions are written for, by the V5 and V4 engines alike. `Ecma262` writes [Corvus.Regex.Ecma262](https://corvus-oss.org/Corvus.Regex.Ecma262/)'s compiled matchers, with the compiled regular expression as data, so nothing is parsed or built when one is first used; a pattern-property field is that library's `Regex`. `DotNet` writes .NET's `System.Text.RegularExpressions`, as earlier versions did, for code that depends on those fields being .NET's `Regex`. | | `--regexEdition` | each dialect's | The edition of ECMA-262 whose grammar every pattern is read with: `Current` or `Es2020`. By default draft 2019-09 and draft 2020-12 (and OpenAPI 3.1) read patterns with the grammar of ECMAScript 2020, which they cite, and the other dialects with today's. `Ecma262` only. | | `--regexUnicodeVersion` | `Default` | The version of Unicode every pattern is read with: `Default` (V8's, 17), `V13`, `V17`, `V18` or `Latest`. `Ecma262` only. | +| `--regexMatchTimeout` | `1000` | The limit, in milliseconds, on one match of a regular expression in generated code, or `-1` for none. A match that runs for longer throws `RegexMatchTimeoutException`. A pattern proved to match in time proportional to the text has no limit whatever this says. Both engines, V5 and V4. The value is fixed when the code is generated: change it and regenerate. | | `--disableOptionalNamingHeuristics` | `false` | Disable all optional naming heuristics at once (see [Naming Heuristics](#naming-heuristics)) | | `--disableNamingHeuristic` | — | Disable a specific naming heuristic by name (repeatable; see [Naming Heuristics](#naming-heuristics)) | | `--useUnixLineEndings` | `false` | Use Unix line endings (`\n`) instead of Windows (`\r\n`) in generated files | @@ -277,7 +278,7 @@ The tool generates: - **Type-safe property accessors**: `person.Name` returns a strongly-typed string value - **Validation**: `person.EvaluateSchema()` validates against the full schema. A `pattern` whose match runs for - longer than 1 second throws `RegexMatchTimeoutException` (see + longer than 1 second (or the limit `--regexMatchTimeout` sets) throws `RegexMatchTimeoutException` (see [SchemaEvaluator.md](SchemaEvaluator.md#what-gets-generated)). A `pattern` or `patternProperties` pattern that is not a valid ECMA-262 regular expression stops the generation with an error that names it (see [RuntimeEvaluator.md](RuntimeEvaluator.md#patterns)). A pattern over a limit of size stops it with an error of its diff --git a/docs/ConsumingGeneratedTypes.md b/docs/ConsumingGeneratedTypes.md index 61b59a1945e..4ef87fb2ed4 100644 --- a/docs/ConsumingGeneratedTypes.md +++ b/docs/ConsumingGeneratedTypes.md @@ -37,6 +37,25 @@ DateTimeOffset when = element.GetDateTimeOffset(); To read a string value's bytes without allocating a managed `string`, use `element.GetUtf8String()` (see the UTF-8 section of [Performance Techniques](./PerformanceTechniques.md)). +### Arrays + +`EnumerateArray()` gives the items of any array-valued type. A **pure array** type, one whose only type is `array` +and which is not a tuple (`prefixItems`), is also an `IReadOnlyCollection` of its item type, so it can be handed +to an API that takes a collection, and `foreach` works on the value itself: + +```csharp +foreach (Order.LineItem item in order.LineItems) +{ + // ... +} + +int count = order.LineItems.Count(); // LINQ, through IReadOnlyCollection +IReadOnlyCollection all = order.LineItems; +``` + +`foreach` over the value uses its own enumerator and does not allocate. LINQ and the interface box the value and its +enumerator, as they do for any struct. + ### Discriminated unions: `Match`, or a `switch` A `oneOf` schema generates a union. Read it with the generated `Match(...)` (or the `IsX` / `AsX` @@ -94,6 +113,28 @@ If a property declares a non-null `default` in its schema, the generated getter property is absent. So express a server-assigned or optional-with-a-default value in the schema rather than hand-writing a null guard at every call site; the generated type carries the default for you. +The getter does not change the document: an absent property stays absent, and a system that reads the JSON +without the schema does not see the default. + +### Writing the defaults into the document: `ApplyDefaults()` + +When the JSON goes to a system that does not apply the schema's defaults itself, call `ApplyDefaults()` on the +mutable element. It **adds additional properties to the document**: each property that is absent and has a +`default` in the schema is added, with the schema's default as its value. It then does the same inside each +property whose type has properties of its own, including an object it has just added from a default. + +```csharp +using JsonDocumentBuilder builder = order.CreateBuilder(workspace); +builder.RootElement.ApplyDefaults(); + +// The document now holds the defaulted properties, ready to send upstream. +string json = builder.RootElement.ToString(); +``` + +A property that is present keeps its value, and a property with no `default` is not added. The items of arrays +are not visited, and the result is not validated: a default that does not satisfy its schema is written as it +is. Calling it again changes nothing. + ## Building a value: convert and construct, never compose-then-parse Do not build a body as a JSON string and `ParseValue` it (an interim string, a parse, and a re-validation). diff --git a/docs/EcmaRegexTranslations.md b/docs/EcmaRegexTranslations.md index 420f1322b0b..86dc4266fe8 100644 --- a/docs/EcmaRegexTranslations.md +++ b/docs/EcmaRegexTranslations.md @@ -497,9 +497,9 @@ such an expression. After a repetition whose iterations hold a lookbehind and ca lazy repetition of a group in a lookbehind: `(?:x*\B){2}(?<=((?:ab)*?)\1)$` never answers for `-a`, and neither does a pattern of the ECMA-262 regular expression test data. The interpreted engine answers both. No rewriting takes a lazy repetition with no highest count out of a pattern, so the engine is chosen instead -(`EcmaRegexTranslator.IsForCompiledEngine`): the evaluator constructs a marked translation without -`RegexOptions.Compiled` whatever its options say, and generated code gives it no `[GeneratedRegex]` form, because -the regular expression generator writes the algorithm of the compiled engine. +(`EcmaRegexTranslator.IsForCompiledEngine`): generated code constructs a marked translation without +`RegexOptions.Compiled` and gives it no `[GeneratedRegex]` form, because the regular expression generator writes the +algorithm of the compiled engine. ## Lookarounds diff --git a/docs/EcmaRegexTranslator.md b/docs/EcmaRegexTranslator.md index 24e0688e6c5..5ae60b4687a 100644 --- a/docs/EcmaRegexTranslator.md +++ b/docs/EcmaRegexTranslator.md @@ -1,11 +1,20 @@ # ECMAScript Regex Translator -> **Scope.** Since V5 and V4 match patterns with Corvus.Regex.Ecma262, the translator is used only where .NET's -> `Regex` is still wanted: V5 and V4 generated code under `--regexEngine DotNet` (MSBuild -> `CorvusTextJsonRegexEngine=DotNet`, or `CorvusJsonSchemaRegexEngine=DotNet` for V4), and -> `JsonSchemaEvaluator.ToDotNetPattern`. The runtime evaluator and the default -> generated code take their answers, validity included, from the library; see -> [RuntimeEvaluator.md](./RuntimeEvaluator.md#patterns). +> **Scope.** Since V5.8.0 the runtime evaluator and the default generated code (V5 and V4) match patterns with +> [Corvus.Regex.Ecma262](https://corvus-oss.org/Corvus.Regex.Ecma262/), and take from it which patterns are valid, +> the limits of size and the limit of a match (see [RuntimeEvaluator.md](./RuntimeEvaluator.md#patterns) and +> [Patterns across the ports](./PatternConformance.md)). The translator is used only where .NET's `Regex` is still +> wanted: +> +> - generated code under `--regexEngine DotNet` (MSBuild `CorvusTextJsonRegexEngine=DotNet`, or +> `CorvusJsonSchemaRegexEngine=DotNet` for V4), including the `[GeneratedRegex]` table of a program generated for +> that engine; +> - `JsonSchemaEvaluator.ToDotNetPattern`. +> +> What this page says of validity, limits, costs and the limit of a match is about those uses. The runtime evaluator +> does not match with a translation. It reads one analysis of the translator's, whether a pattern read without the +> `u` flag can tell a character beyond the Basic Multilingual Plane from two (`CodeUnitsCanChangeTheAnswer`), to +> choose between a matcher of its own and the library. Translation of ECMA-262 regular expressions to .NET regular expression patterns with the same meaning, and the check that a pattern is a valid ECMA-262 regular expression at all. @@ -15,10 +24,12 @@ JSON Schema's `pattern` and `patternProperties` keywords are ECMA-262 regular ex translator writes a .NET pattern with the ECMA-262 meaning for the code that still matches with .NET's `Regex` (see the scope note above). -The answers are tested against V8. The -[ECMA-262 regular expression test data](https://github.com/corvus-dotnet/ecma262-regex-test-data) records what V8 -says about 79,221 patterns and 2,066,549 texts, and the translation gives V8's answer for every one of them in -.NET's compiled and interpreted engines. +The answers are tested against V8. When the translation was the evaluator's (until V5.8.0), it gave V8's answer for +each of the 79,221 patterns and 2,066,549 texts that the +[ECMA-262 regular expression test data](https://github.com/corvus-dotnet/ecma262-regex-test-data) then held, in .NET's +compiled and interpreted engines (the run of 17 October 2026). The data has grown since, and it is Corvus.Regex.Ecma262 +that is run over it now. The translator's own tests check a set of cases chosen from it (`EcmaPatternCases`) in both of +.NET's engines. ## What It Does @@ -51,7 +62,7 @@ says about 79,221 patterns and 2,066,549 texts, and the translation gives V8's a using Corvus.Text.Json.CodeGeneration; using System.Text.RegularExpressions; -// Either grammar: the form the evaluator and the generators use. +// Either grammar: the form generated code uses under the DotNet engine. if (EcmaRegexTranslator.TryTranslate(@"^\d{4}-\d{2}$", out string? dotNetPattern, out string? error)) { Regex regex = new(dotNetPattern!, RegexOptions.CultureInvariant); @@ -64,7 +75,7 @@ else ``` `EcmaRegexTranslator` is internal. Outside the library, `JsonSchemaEvaluator.ToDotNetPattern` gives the translation -the evaluator constructs for a pattern. +of a pattern. ## API Reference @@ -111,19 +122,23 @@ internal static class EcmaRegexTranslator ## Where An Invalid Pattern Is Refused +The runtime evaluator, `Corvus.Text.Json.Validator` and the generators under the default engine refuse a pattern that +is not valid by Corvus.Regex.Ecma262's reading of it (see [RuntimeEvaluator.md](./RuntimeEvaluator.md#patterns)). Where +the translator is used, it refuses the pattern itself: + | Consumer | What happens | |---|---| -| Runtime evaluator (`JsonSchemaEvaluator.Compile`, `CompileFromUri`, `ForEntryPoint`, `FromProgramImage`) | `JsonSchemaCompilationException` when the schema is compiled. The message names the pattern and says what is wrong and where. | -| `Corvus.Text.Json.Validator` | The same exception, from the `JsonSchema.From*` method that compiles the schema. | -| CLI code generator and Roslyn source generator | Generation stops with `InvalidOperationException` (the source generator reports it as its `CRV1001` diagnostic). No code is emitted that would fail when it first validates. | -| V4 code generator (`--engine V4`, `Corvus.Json.SourceGenerator`, `Corvus.Json.Validator`) | The same as the V5 generators: generation stops with `InvalidOperationException`, which its source generator reports as `CRV1001`, with the library's account of what is wrong (or the translator's, under the DotNet engine). | +| CLI code generator and Roslyn source generator, with `--regexEngine DotNet` | Generation stops with `InvalidOperationException` (the source generator reports it as its `CRV1001` diagnostic), with the translator's account of what is wrong and where. No code is emitted that would fail when it first validates. | +| V4 code generator (`--engine V4`, `Corvus.Json.SourceGenerator`), with the DotNet engine | The same: generation stops with `InvalidOperationException`, which its source generator reports as `CRV1001`. | +| `JsonSchemaEvaluator.ToDotNetPattern` | Returns the pattern itself, untranslated. It does not say that the pattern is not valid: check it first if that matters. | ## Limits On The Size Of A Pattern A schema may come from outside, and so may its patterns. No pattern is to make the translator, or .NET when it constructs a regular expression from the translation, run for long or hold much memory. So a pattern has limits of -size (`EcmaRegexLimits`), and a pattern over one of them is refused when the schema is compiled or the code is -generated. The limits are fixed. None of them is an option. +size (`EcmaRegexLimits`), and a pattern over one of them is refused when code is generated for the DotNet engine, +or by `ToDotNetPattern`. The limits are fixed. None of them is an option. (Under the default engine the limits of +size are Corvus.Regex.Ecma262's, which has its own.) | Limit | Value | What it bounds | The message ends | |---|---|---|---| @@ -146,11 +161,10 @@ it is valid. A pattern that nests too deep and is also not valid is refused as t | Consumer | What happens | |---|---| -| Runtime evaluator (`JsonSchemaEvaluator.Compile`, `CompileFromUri`, `ForEntryPoint`, `FromProgramImage`, `ToDotNetPattern`) | `JsonSchemaCompilationException` when the schema is compiled, with that message. | -| `Corvus.Text.Json.Validator` | The same exception, from the `JsonSchema.From*` method that compiles the schema. | -| CLI code generator | Generation stops with an exception whose message names the keyword too: `The pattern '...' of the keyword 'pattern' is a valid ECMA-262 regular expression, and is too large. ...`. Its type derives from `InvalidOperationException`, the type of the error of a pattern that is not valid. | -| Roslyn source generator | The diagnostic `CRV1003`, with that message. A pattern that is not valid is `CRV1001`. | -| V4 code generator (`--engine V4`, `Corvus.Json.SourceGenerator`) | The same as the V5 generators: the exception, and `CRV1003` from its source generator. | +| `JsonSchemaEvaluator.ToDotNetPattern` | `JsonSchemaCompilationException`, with that message. | +| CLI code generator, with `--regexEngine DotNet` | Generation stops with an exception whose message names the keyword too: `The pattern '...' of the keyword 'pattern' is a valid ECMA-262 regular expression, and is too large. ...`. Its type derives from `InvalidOperationException`, the type of the error of a pattern that is not valid. | +| Roslyn source generator, with `CorvusTextJsonRegexEngine=DotNet` | The diagnostic `CRV1003`, with that message. A pattern that is not valid is `CRV1001`. | +| V4 code generator (`--engine V4`, `Corvus.Json.SourceGenerator`), with the DotNet engine | The same as the V5 generators: the exception, and `CRV1003` from its source generator. | ### What an ordinary pattern can meet @@ -206,8 +220,8 @@ a pattern that is too large, or in `RegexMatchTimeoutException`: The eight larger patterns, and forty more of up to a megabyte, are translated or refused in at most 0.31 seconds, and what is accepted of the eight is constructed in at most 45 ms and keeps at most 6.8 MB. At the limits themselves, .NET keeps about 11 bytes for each character -of a translation it interprets, so a translation of 1,048,576 characters keeps about 11 MB for as long as an -evaluator holds it. +of a translation it interprets, so a translation of 1,048,576 characters keeps about 11 MB for as long as the +regular expression is held. A pattern that is over no limit is translated in the steps it takes. The most that a pattern of the [ECMA-262 regular expression test data](https://github.com/corvus-dotnet/ecma262-regex-test-data) takes is 180,606 @@ -216,13 +230,9 @@ steps and a translation of 946,581 characters, for a pattern with six case-insen ## Costs -The translation runs once for each distinct pattern, when a schema is compiled or code is generated. Nothing of it -runs when an instance is matched. The runtime evaluator keeps each pattern's translation and regular expression for -the life of the process, so a pattern that many schemas share is read once. What it keeps is bounded, as a process -may compile schemas from outside for as long as it runs: at most 4,096 patterns and 1,048,576 characters of patterns -and translations, with no pattern or translation longer than 32,768 characters among them. Past either bound -everything kept is let go, and a pattern met again is read again. An evaluator keeps its own regular expressions -for as long as it lives, whatever is let go. +The translation runs once for each distinct pattern, when code is generated for the DotNet engine (or when +`ToDotNetPattern` is called). Nothing of it runs when an instance is matched: generated code holds the translation +as a `[GeneratedRegex]`, or constructs its regular expression from it once, when the type first validates. A translation is usually a little longer than the pattern. It is much longer for a `\p{...}` property with members beyond the Basic Multilingual Plane, which are written out as surrogate pairs (`\p{L}` is about 4,200 characters). @@ -247,12 +257,12 @@ pwsh src/Corvus.Text.Json.CodeGeneration/gen-ecma-unicode-data.ps1 -RegressTable and the translation is under a thousand characters. For a group that can capture any letter (`(.)`, `(\p{L}+)`) it is every class there is, and the translation is about 160,000 characters. .NET's compiled engine would take one to three seconds to compile that at the first match, so a translation longer than 32,768 characters - (`EcmaRegexTranslator.LongestCompiledTranslation`) is interpreted, by the evaluator whatever - `CompileRegularExpressions` says and by generated types where they construct the expression. .NET constructs it - for the interpreter in 10 to 50 milliseconds. Each character compared costs a walk to the end of the input and + (`EcmaRegexTranslator.LongestCompiledTranslation`) is interpreted: generated types construct it without + `RegexOptions.Compiled` and give it no `[GeneratedRegex]` form. .NET constructs it for the interpreter in 10 to 50 + milliseconds. Each character compared costs a walk to the end of the input and back. -- **The engine.** Two kinds of translation are run by .NET's interpreted engine whatever - `CompileRegularExpressions` says, and have no compiled form in generated code: one longer than 32,768 characters +- **The engine.** Two kinds of translation are run by .NET's interpreted engine, and have no compiled form in + generated code: one longer than 32,768 characters (above), and one that keeps a lazy repetition of a group, which starts with `(?#interpreted)`. The compiled engine does not always return from a match of the second kind (see [the translations](./EcmaRegexTranslations.md#repetitions)). Only a pattern with a lazy repetition of a group @@ -262,16 +272,19 @@ pwsh src/Corvus.Text.Json.CodeGeneration/gen-ecma-unicode-data.ps1 -RegressTable it runs. The most the probe above provoked in the second a match is given is 195 MB for the whole process, 160 MB of it the match: a repetition over 110 groups that a backreference reads, on 80,000 characters, in the interpreted engine. .NET has no limit on the memory of a match. Where neither the schema nor the instance is - trusted, set a shorter `RegexMatchTimeout`, bound the length of the instance, or give the process a memory limit. + trusted, generate with a shorter match limit (`--regexMatchTimeout`), bound the length of the instance, or give the + process a memory limit. - **Code that was generated before the match limit has none.** The limit is written into generated code when it is generated, so code generated by an earlier version has none until it is generated again. - **Time.** ECMA-262 does not say how long a match may take, and a backtracking engine can take very long. The - evaluator's match limit (`JsonSchemaEvaluatorOptions.RegexMatchTimeout`, 1 second unless it is set) bounds it, + match limit written into generated code (1 second unless the generator is given another with + `--regexMatchTimeout`, or `CorvusTextJsonRegexMatchTimeout` and `CorvusJsonSchemaRegexMatchTimeout`) bounds it, and a match that reaches it throws `RegexMatchTimeoutException` and gives no answer. V8 answers every text of the ECMA-262 regular expression test data in under 250,000 backtracks. One of its 98,839 patterns is at the limit here: `^a{2}?(((?!)|((|a){2,}(|a)\B|){2,3}?){2,3}.{3}a{2})\4`, whose hardest text takes V8 238,314 - backtracks. It repeats, several deep, a body that matches the empty string in more than one way, and .NET goes - through every way where V8 does too, at many times the cost of a step. The compiled engine takes about 0.7 + backtracks (figures from the runs of the test data when the translation was the evaluator's). It repeats, several + deep, a body that matches the empty string in more than one way, and .NET goes through every way where V8 does + too, at many times the cost of a step. The compiled engine takes about 0.7 seconds for that text and the interpreted one about 1.8 (with a load of 2 to 4 on the machine), most of it the unsetting of a group when each iteration starts and the written-out `\B`. So the interpreted engine meets the limit, and the compiled one meets it on a busy machine: in two runs of the test data with a load of 5 to 7 the diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.Mutable.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.Mutable.cs index e12933990e6..2378076e33a 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.Mutable.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.Mutable.cs @@ -313,6 +313,31 @@ public void SetMessage(scoped in Petstore.Client.Models.JsonString.Source value) _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.cs index dfd201e66fd..7b02a7702f0 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Error.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public Error Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/GetPetsLimit.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/GetPetsLimit.cs index b69e1acff00..f54a904ca38 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/GetPetsLimit.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/GetPetsLimit.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public GetPetsLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt32.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt32.cs index a3d6788c26f..95dcf741ce5 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt32.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt64.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt64.cs index 4c563e45f9c..8d95f7443e2 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt64.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonInt64.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt64 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonString.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonString.cs index 71d6255e9d0..84f1c3e2944 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonString.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.Mutable.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.Mutable.cs index 67f1af73b44..84b979fb3ab 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.Mutable.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.Mutable.cs @@ -322,6 +322,31 @@ public bool RemoveTag() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.cs index 08b023673c4..7da113521c4 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/NewPet.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public NewPet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.Mutable.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.Mutable.cs index e700b84ba0f..6686395b2bc 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.Mutable.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.Mutable.cs @@ -374,6 +374,31 @@ public bool RemoveTag() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.cs index 8be1a9e4a39..69e16974f30 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pet.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public Pet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pets.cs b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pets.cs index 037dc6ef00b..4ed7fc38d16 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pets.cs +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/Models/Pets.cs @@ -18,11 +18,13 @@ namespace Petstore.Client.Models; public readonly partial struct Pets #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public Pets Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/029-OpenApiClient/Generated/corvusjson-openapi.lock b/docs/ExampleRecipes/029-OpenApiClient/Generated/corvusjson-openapi.lock index 4e7265af280..c69f570b30b 100644 --- a/docs/ExampleRecipes/029-OpenApiClient/Generated/corvusjson-openapi.lock +++ b/docs/ExampleRecipes/029-OpenApiClient/Generated/corvusjson-openapi.lock @@ -1,6 +1,6 @@ { "excludePaths": [], - "generatedAt": "2026-10-31T09:00:02.7202387\u002B00:00", + "generatedAt": "2026-11-02T14:19:00.2882624\u002B00:00", "generatedFiles": [ "ListPetsRequest.cs", "ListPetsResponse.cs", @@ -36,7 +36,7 @@ "Models/GetPetsLimit.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includePaths": [], "rootNamespace": "Petstore.Client", "specFileHash": "199092ff57f7e5d812b7164055f1065eb27cdc0a7be4303bea5e4edc070217d8", diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.Mutable.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.Mutable.cs index 5af1d42a2a7..4bf4f83ff85 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.Mutable.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.Mutable.cs @@ -313,6 +313,31 @@ public void SetMessage(scoped in Petstore.Server.Models.JsonString.Source value) _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.cs index 3221d967882..a17de76365a 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Error.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public Error Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/GetPetsLimit.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/GetPetsLimit.cs index 1ce907ff7ae..1172d040642 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/GetPetsLimit.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/GetPetsLimit.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public GetPetsLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt32.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt32.cs index 7c0d4a2f2ac..9b030a22d19 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt32.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt64.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt64.cs index ae64eb3ee21..bddff96c325 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt64.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonInt64.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt64 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonString.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonString.cs index af63fbbb04c..6ac7dadac45 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonString.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.Mutable.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.Mutable.cs index c0e32ae9be6..8b4fff410a8 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.Mutable.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.Mutable.cs @@ -322,6 +322,31 @@ public bool RemoveTag() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.cs index 7aa46397403..ada738b8d04 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/NewPet.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public NewPet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.Mutable.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.Mutable.cs index 7d4a74afb54..a444713d641 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.Mutable.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.Mutable.cs @@ -374,6 +374,31 @@ public bool RemoveTag() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.cs index 3e330febc0b..fea034812b1 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pet.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public Pet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pets.cs b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pets.cs index 64995af56dd..a8f4f271469 100644 --- a/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pets.cs +++ b/docs/ExampleRecipes/030-OpenApiServer/Generated/Models/Pets.cs @@ -18,11 +18,13 @@ namespace Petstore.Server.Models; public readonly partial struct Pets #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public Pets Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.Mutable.cs index 91609c82dda..72e4e2df5d2 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.Mutable.cs @@ -426,6 +426,31 @@ public void SetType(scoped in Petstore.Extended.Models.ActivityEvent.TypeEntity. _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.TypeEntity.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.TypeEntity.cs index 39841493e0b..7b10fd5d1f1 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.TypeEntity.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.TypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.cs index f10749c1d25..8eaa248b438 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ActivityEvent.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ActivityEvent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.Mutable.cs index a6c18cc805b..e3fa5571efe 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.Mutable.cs @@ -383,6 +383,31 @@ public void SetId(scoped in Petstore.Extended.Models.JsonString.Source value) _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.cs index 6c1f95464c4..39dcc6feed2 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/ChatChunk.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public ChatChunk Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.Mutable.cs index 0f07bf1a281..62dea7fb39a 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.Mutable.cs @@ -313,6 +313,31 @@ public void SetMessage(scoped in Petstore.Extended.Models.JsonString.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.cs index 9ad11740594..fdb1b02905d 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Error.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public Error Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsBatchByIdsIds.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsBatchByIdsIds.cs index f7d38e6fcd7..41e8ccd30e3 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsBatchByIdsIds.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsBatchByIdsIds.cs @@ -18,11 +18,13 @@ namespace Petstore.Extended.Models; public readonly partial struct GetPetsBatchByIdsIds #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -100,6 +102,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -313,6 +330,12 @@ private void CheckValidInstance() public GetPetsBatchByIdsIds Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.Mutable.cs index 43c02d8e21f..63e1c5dc625 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.Mutable.cs @@ -453,6 +453,31 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.StatusEntity.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.StatusEntity.cs index e04aa412f45..0775a21704b 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.StatusEntity.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.cs index d5ffe53c06d..33832b99586 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsFilter.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public GetPetsFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsLimit.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsLimit.cs index c49f7e4ec3a..b46400ccf13 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsLimit.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsLimit.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public GetPetsLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsTags.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsTags.cs index 8e2ee575730..88945b7e0c5 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsTags.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/GetPetsTags.cs @@ -18,11 +18,13 @@ namespace Petstore.Extended.Models; public readonly partial struct GetPetsTags #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public GetPetsTags Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBinary.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBinary.cs index 96a1e1f8906..711f3d44778 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBinary.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBinary.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonBinary Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBoolean.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBoolean.cs index 55dce493dd3..0d4ff8b92e9 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBoolean.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonDateTime.cs index e550fb98e7e..b631d7674e6 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonDateTime.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonEmail.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonEmail.cs index cfdb913f37a..ce0982c7ad6 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonEmail.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonEmail.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonEmail Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt32.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt32.cs index ed5b9f178c1..c35669e885c 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt32.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt64.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt64.cs index 58291527fa9..9e1415cf82f 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt64.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInt64.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt64 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInteger.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInteger.cs index c86ca6c77c3..13983bd917d 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInteger.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonInteger.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonString.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonString.cs index 815b34bcd8e..9e270407c63 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonString.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.JsonStringArray.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.JsonStringArray.cs index dd6c63ce553..2e1b88fce94 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.JsonStringArray.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct NewPet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.Mutable.cs index f4cc484a6d0..9648e677a90 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.Mutable.cs @@ -532,6 +532,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.StatusEntity.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.StatusEntity.cs index 9997cb784c0..e27d7f22a21 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.StatusEntity.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.cs index 438aa690d30..ad0c1efb8ef 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/NewPet.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public NewPet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.JsonStringArray.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.JsonStringArray.cs index 5d20b80b81a..d578206fdaf 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.JsonStringArray.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.Mutable.cs index 94371f90d0e..930ab1433df 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.Mutable.cs @@ -681,6 +681,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.StatusEntity.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.StatusEntity.cs index 04442f1b561..0e5706adcb2 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.StatusEntity.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.TagsJsonStArray.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.TagsJsonStArray.cs index 4a6e827ccf5..0c85228f007 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.TagsJsonStArray.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.TagsJsonStArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct TagsJsonStArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public TagsJsonStArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.cs index eb9626c292f..6ce393da035 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/Pet.cs @@ -463,6 +463,12 @@ private void CheckValidInstance() public Pet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PetList.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PetList.cs index 8f68ed50372..3cd9cc66c74 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PetList.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PetList.cs @@ -18,11 +18,13 @@ namespace Petstore.Extended.Models; public readonly partial struct PetList #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public PetList Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.Mutable.cs index e44880e4734..abc391dabfd 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.Mutable.cs @@ -487,6 +487,31 @@ public void SetUploadedAt(scoped in Petstore.Extended.Models.JsonDateTime.Source _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.cs index b86daad6ddc..2e98c7ff154 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PhotoMetadata.cs @@ -431,6 +431,12 @@ private void CheckValidInstance() public PhotoMetadata Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs index ce2abc8eeba..1c6b84a558c 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs @@ -374,6 +374,31 @@ public void SetStatus(scoped in Petstore.Extended.Models.PostAdoptionApplyAccept _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs index a4796a6b2c0..a6543fc33a6 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.cs index a43eead4cf9..d77e6283579 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyAccepted.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public PostAdoptionApplyAccepted Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs index b2c917383d7..84e00b2cd3a 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public HousingTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.Mutable.cs index b705fa515e5..ff0687c2909 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.Mutable.cs @@ -600,6 +600,31 @@ public bool RemovePhone() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.cs index 9dfe8e94c49..793a004c654 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostAdoptionApplyBody.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public PostAdoptionApplyBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs index a7eeaf0a29d..54e7ac4b5f3 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs @@ -358,6 +358,31 @@ public void SetMessage(scoped in Petstore.Extended.Models.JsonString.Source valu _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs index cfcbb98f346..52ad47c52ff 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs @@ -318,6 +318,31 @@ public void SetRole(scoped in Petstore.Extended.Models.PostPetsByPetIdChatBody.R _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs index a1bc367dfae..cfcc9244f9b 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public RoleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs index 3a58f336303..4d5dc36b7a9 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredContentAndRole Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs index c1aa52d4ae1..c5cdb886023 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs @@ -21,11 +21,13 @@ public readonly partial struct PostPetsByPetIdChatBody public readonly partial struct RequiredContentAndRoleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public RequiredContentAndRoleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.cs index d2bdc39f95a..0ff4c330bcc 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdChatBody.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public PostPetsByPetIdChatBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs index 513c004c871..0195c60b898 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs @@ -383,6 +383,31 @@ public bool RemoveIsPrimary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.cs b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.cs index 9dac38eb393..62f3c1126db 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.cs +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/Models/PostPetsByPetIdPhotosBody.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public PostPetsByPetIdPhotosBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/corvusjson-openapi.lock b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/corvusjson-openapi.lock index cd0d5287f98..d85ce7a700e 100644 --- a/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/corvusjson-openapi.lock +++ b/docs/ExampleRecipes/031-OpenApiAdvancedClient/Generated/corvusjson-openapi.lock @@ -1,6 +1,6 @@ { "excludePaths": [], - "generatedAt": "2026-10-31T09:00:04.5319676\u002B00:00", + "generatedAt": "2026-11-02T14:19:02.8467637\u002B00:00", "generatedFiles": [ "ListPetsRequest.cs", "ListPetsResponse.cs", @@ -135,7 +135,7 @@ "Models/PostPetsByPetIdPhotosBody.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includePaths": [], "rootNamespace": "Petstore.Extended", "specFileHash": "27f81b7eb15fe66d4e3b2ffb3572a80fe7e0c6b564966f8b785c7496c1631ff8", diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.Mutable.cs index 49795e200e2..c0ccc8fa4ba 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.Mutable.cs @@ -426,6 +426,31 @@ public void SetType(scoped in Petstore.Extended.Server.Models.ActivityEvent.Type _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.TypeEntity.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.TypeEntity.cs index dcb142c8a9b..ce1460f3ab3 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.TypeEntity.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.TypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.cs index 9417fa93e46..c332d1ffe7c 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ActivityEvent.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ActivityEvent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.Mutable.cs index 03b5df5215b..8a29d6a4ec5 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.Mutable.cs @@ -383,6 +383,31 @@ public void SetId(scoped in Petstore.Extended.Server.Models.JsonString.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.cs index 89c2aff6fad..f67b23289ac 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/ChatChunk.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public ChatChunk Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.Mutable.cs index c39c4c32a34..65f33fbe8f5 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.Mutable.cs @@ -313,6 +313,31 @@ public void SetMessage(scoped in Petstore.Extended.Server.Models.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.cs index 65b3de1d695..0722ea92f5d 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Error.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public Error Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsBatchByIdsIds.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsBatchByIdsIds.cs index d96534f12d9..0689af2ebfa 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsBatchByIdsIds.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsBatchByIdsIds.cs @@ -18,11 +18,13 @@ namespace Petstore.Extended.Server.Models; public readonly partial struct GetPetsBatchByIdsIds #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -100,6 +102,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -313,6 +330,12 @@ private void CheckValidInstance() public GetPetsBatchByIdsIds Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.Mutable.cs index 165f2cfb2b6..a6c94690433 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.Mutable.cs @@ -453,6 +453,31 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.StatusEntity.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.StatusEntity.cs index 3c3863ee7ee..4624cd3bd14 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.StatusEntity.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.cs index 64acc1dc64e..14dfb8e3ee7 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsFilter.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public GetPetsFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsLimit.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsLimit.cs index a183334642f..20c2e857bbe 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsLimit.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsLimit.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public GetPetsLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsTags.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsTags.cs index 7af90a5e4c8..dc10f4b2a35 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsTags.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/GetPetsTags.cs @@ -18,11 +18,13 @@ namespace Petstore.Extended.Server.Models; public readonly partial struct GetPetsTags #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public GetPetsTags Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBinary.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBinary.cs index 1b57e3352bc..d91abf646df 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBinary.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBinary.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonBinary Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBoolean.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBoolean.cs index 0014fb1cec7..2bed54dee8e 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBoolean.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonDateTime.cs index 5c5907fc840..bf223efb823 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonDateTime.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonEmail.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonEmail.cs index 41a2a3b6211..a6fa76c7dc2 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonEmail.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonEmail.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonEmail Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt32.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt32.cs index b442208d623..b03fcac9b8d 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt32.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt64.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt64.cs index bd47b182ca6..c7d3059ce47 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt64.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInt64.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt64 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInteger.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInteger.cs index 58a961087e9..93ba3fd3341 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInteger.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonInteger.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonString.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonString.cs index 80417dbd1d9..dbbf827867d 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonString.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.JsonStringArray.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.JsonStringArray.cs index 3911cce3cd0..c4d2e868ad5 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.JsonStringArray.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct NewPet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.Mutable.cs index c2a535809b7..0f33ce00708 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.Mutable.cs @@ -532,6 +532,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.StatusEntity.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.StatusEntity.cs index 1f90c6a868f..65664c465ba 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.StatusEntity.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.cs index 7a3034bea2f..5d75b0f5bd6 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/NewPet.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public NewPet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.JsonStringArray.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.JsonStringArray.cs index 0d42c13867d..4870c3d3224 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.JsonStringArray.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.Mutable.cs index 39c4ac0dd06..3c492899c92 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.Mutable.cs @@ -681,6 +681,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.StatusEntity.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.StatusEntity.cs index 233ec0c5d9d..eb65a902592 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.StatusEntity.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.TagsJsonStArray.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.TagsJsonStArray.cs index b452cfc3ed6..d1e4c73820e 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.TagsJsonStArray.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.TagsJsonStArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct TagsJsonStArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public TagsJsonStArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.cs index 73a793b82d1..6f98aab5ead 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/Pet.cs @@ -463,6 +463,12 @@ private void CheckValidInstance() public Pet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PetList.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PetList.cs index ff9b4e8781c..9a5cce7e01d 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PetList.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PetList.cs @@ -18,11 +18,13 @@ namespace Petstore.Extended.Server.Models; public readonly partial struct PetList #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public PetList Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.Mutable.cs index c5384a354f7..db4ea12d976 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.Mutable.cs @@ -487,6 +487,31 @@ public void SetUploadedAt(scoped in Petstore.Extended.Server.Models.JsonDateTime _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.cs index e06e2fd7bb3..5ef111d2f9e 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PhotoMetadata.cs @@ -431,6 +431,12 @@ private void CheckValidInstance() public PhotoMetadata Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs index 781e779cb78..eb4f7593373 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.Mutable.cs @@ -374,6 +374,31 @@ public void SetStatus(scoped in Petstore.Extended.Server.Models.PostAdoptionAppl _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs index 2c3dcb04648..111470008d7 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.cs index 6d56139f8ec..2f27deb8271 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyAccepted.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public PostAdoptionApplyAccepted Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs index 3e9b220c985..7aff0653c32 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.HousingTypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public HousingTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.Mutable.cs index dc2f36a93df..5d18e8408b8 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.Mutable.cs @@ -600,6 +600,31 @@ public bool RemovePhone() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.cs index 59e09b241b3..024c1cdf7e5 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostAdoptionApplyBody.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public PostAdoptionApplyBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs index d6fdcd98b44..c58204fd30b 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.Mutable.cs @@ -358,6 +358,31 @@ public void SetMessage(scoped in Petstore.Extended.Server.Models.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs index 5516d345303..4581290e0b5 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs @@ -318,6 +318,31 @@ public void SetRole(scoped in Petstore.Extended.Server.Models.PostPetsByPetIdCha _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs index dd5c13663cc..2b113fd01fd 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public RoleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs index e0e7bdf1610..045af4d19ce 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredContentAndRole Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs index a86c3b73030..f2ea1462b1d 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs @@ -21,11 +21,13 @@ public readonly partial struct PostPetsByPetIdChatBody public readonly partial struct RequiredContentAndRoleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public RequiredContentAndRoleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.cs index b93eb665f9a..4b540f7d6e5 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdChatBody.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public PostPetsByPetIdChatBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs index 3d649490609..7838702234f 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.Mutable.cs @@ -383,6 +383,31 @@ public bool RemoveIsPrimary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.cs b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.cs index c3e5813132c..399aa0a3d9c 100644 --- a/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.cs +++ b/docs/ExampleRecipes/032-OpenApiAdvancedServer/Generated/Models/PostPetsByPetIdPhotosBody.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public PostPetsByPetIdPhotosBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.Mutable.cs index c14176c8baf..a7af6dd4438 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.Mutable.cs @@ -426,6 +426,31 @@ public void SetType(scoped in Petstore.EndToEnd.Client.Models.ActivityEvent.Type _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.TypeEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.TypeEntity.cs index 33754802650..4ce97b8a922 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.TypeEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.TypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.cs index 70058b5dea9..d20d6949cb0 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ActivityEvent.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ActivityEvent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.Mutable.cs index 122eb4ea082..5e6eb65fc4d 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.Mutable.cs @@ -383,6 +383,31 @@ public void SetId(scoped in Petstore.EndToEnd.Client.Models.JsonString.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.cs index 6afbd58d163..96a27db6d92 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/ChatChunk.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public ChatChunk Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.Mutable.cs index df6af7d2d23..4514d453452 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.Mutable.cs @@ -313,6 +313,31 @@ public void SetMessage(scoped in Petstore.EndToEnd.Client.Models.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.cs index c3ad18544ae..7d55bb10406 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Error.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public Error Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsBatchByIdsIds.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsBatchByIdsIds.cs index d30cdad77a8..7cfd0d4bf5b 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsBatchByIdsIds.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsBatchByIdsIds.cs @@ -18,11 +18,13 @@ namespace Petstore.EndToEnd.Client.Models; public readonly partial struct GetPetsBatchByIdsIds #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -100,6 +102,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -313,6 +330,12 @@ private void CheckValidInstance() public GetPetsBatchByIdsIds Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.Mutable.cs index 854e3b2040e..92de1eaaa6c 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.Mutable.cs @@ -453,6 +453,31 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.StatusEntity.cs index 591de9fc7d0..ef32dbeecfd 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.cs index e9a1dc304f5..00ac6da5f23 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsFilter.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public GetPetsFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsLimit.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsLimit.cs index 5063e9efc09..485a6b2ed02 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsLimit.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsLimit.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public GetPetsLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsTags.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsTags.cs index 214b024c845..2b3894f7713 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsTags.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/GetPetsTags.cs @@ -18,11 +18,13 @@ namespace Petstore.EndToEnd.Client.Models; public readonly partial struct GetPetsTags #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public GetPetsTags Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBinary.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBinary.cs index dadd17c1bb5..3a13142b594 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBinary.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBinary.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonBinary Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBoolean.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBoolean.cs index 405f6bd96e5..f44f7cb0c78 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBoolean.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonDateTime.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonDateTime.cs index 67bbe70007a..8077eed33ac 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonDateTime.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonEmail.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonEmail.cs index 327816fa5a4..d6911c719f0 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonEmail.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonEmail.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonEmail Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt32.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt32.cs index 9ff240afa2f..f05fc2b9b91 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt32.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt64.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt64.cs index 76764bc5db1..96df50ad570 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt64.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInt64.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt64 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInteger.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInteger.cs index 54005cfff1e..53792f2b2dc 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInteger.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonInteger.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonString.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonString.cs index b3ac9cfc858..f4600137d52 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonString.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.JsonStringArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.JsonStringArray.cs index 2db8374a974..21ace07f9b1 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.JsonStringArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct NewPet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.Mutable.cs index e666ba4a81a..eac50b385cc 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.Mutable.cs @@ -532,6 +532,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.StatusEntity.cs index 3a5d9fbc167..a20d9c8f188 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.cs index f4ce626c26d..d084409a7f9 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/NewPet.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public NewPet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.JsonStringArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.JsonStringArray.cs index dc2a050b9e1..6592510ce8a 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.JsonStringArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.Mutable.cs index 8a50b987efa..eccd5297f67 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.Mutable.cs @@ -681,6 +681,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.StatusEntity.cs index f87de285bff..1e8b22b526b 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.TagsJsonStArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.TagsJsonStArray.cs index a4b261c05dc..c83dc73a2f7 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.TagsJsonStArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.TagsJsonStArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct TagsJsonStArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public TagsJsonStArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.cs index f32f0a51c43..38d2c787819 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/Pet.cs @@ -463,6 +463,12 @@ private void CheckValidInstance() public Pet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PetList.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PetList.cs index 414bdc9e28d..73406ed8e2a 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PetList.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PetList.cs @@ -18,11 +18,13 @@ namespace Petstore.EndToEnd.Client.Models; public readonly partial struct PetList #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public PetList Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.Mutable.cs index 5f53def3e19..ed15e8d7a65 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.Mutable.cs @@ -487,6 +487,31 @@ public void SetUploadedAt(scoped in Petstore.EndToEnd.Client.Models.JsonDateTime _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.cs index 88341ebe464..1ba141ca477 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PhotoMetadata.cs @@ -431,6 +431,12 @@ private void CheckValidInstance() public PhotoMetadata Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.Mutable.cs index 09b3eaa6815..ea2ab1b7eff 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.Mutable.cs @@ -374,6 +374,31 @@ public void SetStatus(scoped in Petstore.EndToEnd.Client.Models.PostAdoptionAppl _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.StatusEntity.cs index a126012571f..0cd7172f7d2 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.cs index 6f56464e559..91c910c2eac 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyAccepted.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public PostAdoptionApplyAccepted Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.HousingTypeEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.HousingTypeEntity.cs index 3c665cff3d1..4edda0567cd 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.HousingTypeEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.HousingTypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public HousingTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.Mutable.cs index 2428450ab3b..e1bfd886642 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.Mutable.cs @@ -600,6 +600,31 @@ public bool RemovePhone() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.cs index 2a4fd4a31bd..78c043114ee 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostAdoptionApplyBody.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public PostAdoptionApplyBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.Mutable.cs index 1f921a03320..e1d4009dacf 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.Mutable.cs @@ -358,6 +358,31 @@ public void SetMessage(scoped in Petstore.EndToEnd.Client.Models.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs index b0de86a615f..0f1f62f7270 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs @@ -318,6 +318,31 @@ public void SetRole(scoped in Petstore.EndToEnd.Client.Models.PostPetsByPetIdCha _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs index cb93852539e..c78819ebad5 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public RoleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs index 9d2315b6cd7..0e1a378c3f8 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredContentAndRole Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs index e5ab598cee7..d84acb16f3e 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs @@ -21,11 +21,13 @@ public readonly partial struct PostPetsByPetIdChatBody public readonly partial struct RequiredContentAndRoleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public RequiredContentAndRoleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.cs index dcaf6871c9b..6c7458136d9 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdChatBody.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public PostPetsByPetIdChatBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.Mutable.cs index 48fde8fcca1..3aee6440e80 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.Mutable.cs @@ -383,6 +383,31 @@ public bool RemoveIsPrimary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.cs index 2ce44a31f23..59712b3f784 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/Models/PostPetsByPetIdPhotosBody.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public PostPetsByPetIdPhotosBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/corvusjson-openapi.lock b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/corvusjson-openapi.lock index 02a66e2750d..e4477b2e0d2 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/corvusjson-openapi.lock +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Client/corvusjson-openapi.lock @@ -1,6 +1,6 @@ { "excludePaths": [], - "generatedAt": "2026-10-31T09:00:06.4029459\u002B00:00", + "generatedAt": "2026-11-02T14:19:05.4239484\u002B00:00", "generatedFiles": [ "ListPetsRequest.cs", "ListPetsResponse.cs", @@ -135,7 +135,7 @@ "Models/PostPetsByPetIdPhotosBody.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includePaths": [], "rootNamespace": "Petstore.EndToEnd.Client", "specFileHash": "27f81b7eb15fe66d4e3b2ffb3572a80fe7e0c6b564966f8b785c7496c1631ff8", diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.Mutable.cs index 906ce99c9be..3c3b8b3346a 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.Mutable.cs @@ -426,6 +426,31 @@ public void SetType(scoped in Petstore.EndToEnd.Server.Models.ActivityEvent.Type _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.TypeEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.TypeEntity.cs index fd42c21b1f0..6cd1fe1b75f 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.TypeEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.TypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public TypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.cs index 425ef273da9..f18fa42b2e8 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ActivityEvent.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public ActivityEvent Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.Mutable.cs index b2ef36ac36a..8cfce0f64c3 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.Mutable.cs @@ -383,6 +383,31 @@ public void SetId(scoped in Petstore.EndToEnd.Server.Models.JsonString.Source va _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.cs index 9154b7df588..ae7318a7f58 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/ChatChunk.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public ChatChunk Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.Mutable.cs index 8d1128c0bd1..b9d4dc63e3e 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.Mutable.cs @@ -313,6 +313,31 @@ public void SetMessage(scoped in Petstore.EndToEnd.Server.Models.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.cs index b45bfd5a3e2..9cf338fe720 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Error.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public Error Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsBatchByIdsIds.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsBatchByIdsIds.cs index 2c47360a4f2..eaf0b770283 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsBatchByIdsIds.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsBatchByIdsIds.cs @@ -18,11 +18,13 @@ namespace Petstore.EndToEnd.Server.Models; public readonly partial struct GetPetsBatchByIdsIds #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -100,6 +102,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -313,6 +330,12 @@ private void CheckValidInstance() public GetPetsBatchByIdsIds Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.Mutable.cs index 3e6c8290b3a..29599c7fd0a 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.Mutable.cs @@ -453,6 +453,31 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.StatusEntity.cs index f763fff26e2..291fb60f4f8 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.cs index f6596437037..443c5f1afdb 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsFilter.cs @@ -400,6 +400,12 @@ private void CheckValidInstance() public GetPetsFilter Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsLimit.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsLimit.cs index 2f61309fbf6..0aa5e0862bf 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsLimit.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsLimit.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public GetPetsLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsTags.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsTags.cs index 50b539a112b..e1a95a1780c 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsTags.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/GetPetsTags.cs @@ -18,11 +18,13 @@ namespace Petstore.EndToEnd.Server.Models; public readonly partial struct GetPetsTags #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public GetPetsTags Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBinary.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBinary.cs index 5d8f37f8741..9dcb4fc44ff 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBinary.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBinary.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonBinary Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBoolean.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBoolean.cs index 9f83b0d0ca2..8f584272ce8 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBoolean.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonBoolean.cs @@ -298,6 +298,12 @@ private void CheckValidInstance() public JsonBoolean Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonDateTime.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonDateTime.cs index e6525636644..607c0a6b749 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonDateTime.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonEmail.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonEmail.cs index b5c68261891..b3f512f30ed 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonEmail.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonEmail.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonEmail Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt32.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt32.cs index 24239199ba1..0f48f2d25a0 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt32.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt64.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt64.cs index 0e047035ade..ef43ced32a0 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt64.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInt64.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt64 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInteger.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInteger.cs index 8c34b1c4233..eaca74fdb6c 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInteger.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonInteger.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public JsonInteger Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonString.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonString.cs index b93d6670d41..56841443e2a 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonString.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.JsonStringArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.JsonStringArray.cs index 861f01d7506..b074591522e 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.JsonStringArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct NewPet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.Mutable.cs index 846c9f095dd..01c409b3001 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.Mutable.cs @@ -532,6 +532,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.StatusEntity.cs index 87045b8424f..612b9b8ab3d 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.cs index 4263085e79a..7cb9f8187bb 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/NewPet.cs @@ -426,6 +426,12 @@ private void CheckValidInstance() public NewPet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.JsonStringArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.JsonStringArray.cs index e10c7f22bcf..2cab33e9f22 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.JsonStringArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.JsonStringArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct JsonStringArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public JsonStringArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.Mutable.cs index dce31878a64..6ae158063a7 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.Mutable.cs @@ -681,6 +681,31 @@ public bool RemoveTags() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.StatusEntity.cs index 872d019ca2a..90705bb8a06 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.TagsJsonStArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.TagsJsonStArray.cs index a744002bdd4..823028f27bb 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.TagsJsonStArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.TagsJsonStArray.cs @@ -21,11 +21,13 @@ public readonly partial struct Pet public readonly partial struct TagsJsonStArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public TagsJsonStArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.cs index 5482812a5ad..14a2aecc96b 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/Pet.cs @@ -463,6 +463,12 @@ private void CheckValidInstance() public Pet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PetList.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PetList.cs index 5c90b39ebdb..25c6498e23a 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PetList.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PetList.cs @@ -18,11 +18,13 @@ namespace Petstore.EndToEnd.Server.Models; public readonly partial struct PetList #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public PetList Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.Mutable.cs index 54d2b157cd6..0f047e7ae36 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.Mutable.cs @@ -487,6 +487,31 @@ public void SetUploadedAt(scoped in Petstore.EndToEnd.Server.Models.JsonDateTime _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.cs index 98020895f1b..3346459ad8c 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PhotoMetadata.cs @@ -431,6 +431,12 @@ private void CheckValidInstance() public PhotoMetadata Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.Mutable.cs index 6c2196fdbc2..54496b8f36b 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.Mutable.cs @@ -374,6 +374,31 @@ public void SetStatus(scoped in Petstore.EndToEnd.Server.Models.PostAdoptionAppl _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.StatusEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.StatusEntity.cs index 0222e68afc9..75c2cb570a2 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.StatusEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.cs index cef05c6acb2..b236126e0a7 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyAccepted.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public PostAdoptionApplyAccepted Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.HousingTypeEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.HousingTypeEntity.cs index ff503952e15..8d949ce71c6 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.HousingTypeEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.HousingTypeEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public HousingTypeEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.Mutable.cs index 1e365879b03..fa53ebf3917 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.Mutable.cs @@ -600,6 +600,31 @@ public bool RemovePhone() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.cs index 671f9157389..474197ba3dd 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostAdoptionApplyBody.cs @@ -468,6 +468,12 @@ private void CheckValidInstance() public PostAdoptionApplyBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.Mutable.cs index 0e15ff9484f..fc3b747b764 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.Mutable.cs @@ -358,6 +358,31 @@ public void SetMessage(scoped in Petstore.EndToEnd.Server.Models.JsonString.Sour _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs index 7c315ddcb69..c716a526d67 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.Mutable.cs @@ -318,6 +318,31 @@ public void SetRole(scoped in Petstore.EndToEnd.Server.Models.PostPetsByPetIdCha _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs index 8109b78b693..8310707e4f6 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.RoleEntity.cs @@ -317,6 +317,12 @@ private void CheckValidInstance() public RoleEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs index bf67f7e2606..495159a5c21 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.RequiredContentAndRole.cs @@ -383,6 +383,12 @@ private void CheckValidInstance() public RequiredContentAndRole Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs index 20ec8a2413b..1015b00140f 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.RequiredContentAndRoleArray.cs @@ -21,11 +21,13 @@ public readonly partial struct PostPetsByPetIdChatBody public readonly partial struct RequiredContentAndRoleArray #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -75,6 +77,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -288,6 +305,12 @@ private void CheckValidInstance() public RequiredContentAndRoleArray Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.cs index f7f8d5f934a..3cbe97c8669 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdChatBody.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public PostPetsByPetIdChatBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.Mutable.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.Mutable.cs index e35c72fdac5..02784360150 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.Mutable.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.Mutable.cs @@ -383,6 +383,31 @@ public bool RemoveIsPrimary() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.cs b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.cs index 84da1d763da..d141be87756 100644 --- a/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.cs +++ b/docs/ExampleRecipes/033-OpenApiEndToEnd/Generated/Server/Models/PostPetsByPetIdPhotosBody.cs @@ -389,6 +389,12 @@ private void CheckValidInstance() public PostPetsByPetIdPhotosBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonDateTime.cs index f4f9ea49543..6f73b0c8a56 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonDateTime.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonObject.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonObject.cs index 8119f0a82be..d6459af1f1d 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonObject.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonString.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonString.cs index d71065e90ff..d68a26c809a 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonString.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.Mutable.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.Mutable.cs index 3eacec0f09c..8e6da2b99c2 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.Mutable.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.Mutable.cs @@ -365,6 +365,31 @@ public void SetSeverity(scoped in EventSubscription.CallbackServer.Models.Schema _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.SeverityEntity.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.SeverityEntity.cs index 7b9556d215d..32dcbae2866 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.SeverityEntity.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.SeverityEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SeverityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.cs index fb758e20e21..6f60815d18f 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public Schema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.Mutable.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.Mutable.cs index 1a63b03908d..c4bdf2df484 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.Mutable.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.Mutable.cs @@ -462,6 +462,31 @@ public void SetTimestamp(scoped in EventSubscription.CallbackServer.Models.JsonD _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.cs b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.cs index 07c8c6aea9b..62174f16a7c 100644 --- a/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.cs +++ b/docs/ExampleRecipes/034-OpenApiCallbackServer/Generated/Models/Schema1.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public Schema1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonDateTime.cs index 8b72feabe2b..542da6eced5 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonDateTime.cs @@ -372,6 +372,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonObject.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonObject.cs index 65e67a12207..1a8278e1b2a 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonObject.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonObject.cs @@ -336,6 +336,12 @@ private void CheckValidInstance() public JsonObject Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonString.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonString.cs index 658b2d0001e..cb0f337a480 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonString.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.Mutable.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.Mutable.cs index 91f548b6cf8..bf9499e9647 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.Mutable.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.Mutable.cs @@ -365,6 +365,31 @@ public void SetSeverity(scoped in EventSubscription.CallbackClient.Models.Schema _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.SeverityEntity.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.SeverityEntity.cs index 0ff4022e1a1..ff75e73fd18 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.SeverityEntity.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.SeverityEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public SeverityEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.cs index 3acc52f2910..046a3460985 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema.cs @@ -399,6 +399,12 @@ private void CheckValidInstance() public Schema Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.Mutable.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.Mutable.cs index 2019a2d8b56..2bbe88c8254 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.Mutable.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.Mutable.cs @@ -462,6 +462,31 @@ public void SetTimestamp(scoped in EventSubscription.CallbackClient.Models.JsonD _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.cs b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.cs index ddea4f1108a..f9e42d0dc36 100644 --- a/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.cs +++ b/docs/ExampleRecipes/035-OpenApiCallbackClient/Generated/Models/Schema1.cs @@ -415,6 +415,12 @@ private void CheckValidInstance() public Schema1 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/JsonDateTime.cs index f210d44f55b..2184a9ef0ef 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/JsonDateTime.cs @@ -377,6 +377,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs index 2da6fcb257f..fda97c59df6 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public LightIntensityMeasuredInLumens Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.Mutable.cs b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.Mutable.cs index ecc02ce29e4..99e461f5a8a 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.Mutable.cs +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.cs b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.cs index fc8fafba442..d6f2eee01a2 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.cs +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/LightMeasuredPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public LightMeasuredPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.Mutable.cs b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.Mutable.cs index 1827fc0dec4..a37276a0587 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.Mutable.cs +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs index c02bcd2be89..334adefce53 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WhetherToTurnOnOrOffTheLight Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.cs b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.cs index 2aab06bcdb2..dcd71eb170a 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.cs +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/Models/TurnOnOffPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public TurnOnOffPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/corvusjson-asyncapi.lock b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/corvusjson-asyncapi.lock index b13d84d6248..8f6f6281d4a 100644 --- a/docs/ExampleRecipes/036-AsyncApiProducer/Generated/corvusjson-asyncapi.lock +++ b/docs/ExampleRecipes/036-AsyncApiProducer/Generated/corvusjson-asyncapi.lock @@ -1,6 +1,6 @@ { "excludeChannels": [], - "generatedAt": "2026-10-31T09:00:10.0345530\u002B00:00", + "generatedAt": "2026-11-02T14:19:10.1524619\u002B00:00", "generatedFiles": [ "TurnOnProducer.cs", "IReceiveLightMeasurementHandler.cs", @@ -26,7 +26,7 @@ "Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includeChannels": [], "mode": "both", "rootNamespace": "Streetlights.Client", diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/JsonDateTime.cs index f210d44f55b..2184a9ef0ef 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/JsonDateTime.cs @@ -377,6 +377,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs index 2da6fcb257f..fda97c59df6 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public LightIntensityMeasuredInLumens Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.Mutable.cs b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.Mutable.cs index ecc02ce29e4..99e461f5a8a 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.Mutable.cs +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.cs b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.cs index fc8fafba442..d6f2eee01a2 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.cs +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/LightMeasuredPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public LightMeasuredPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.Mutable.cs b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.Mutable.cs index 1827fc0dec4..a37276a0587 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.Mutable.cs +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs index c02bcd2be89..334adefce53 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WhetherToTurnOnOrOffTheLight Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.cs b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.cs index 2aab06bcdb2..dcd71eb170a 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.cs +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/Models/TurnOnOffPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public TurnOnOffPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/corvusjson-asyncapi.lock b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/corvusjson-asyncapi.lock index 0afca0c904c..97f6fa31233 100644 --- a/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/corvusjson-asyncapi.lock +++ b/docs/ExampleRecipes/037-AsyncApiConsumer/Generated/corvusjson-asyncapi.lock @@ -1,6 +1,6 @@ { "excludeChannels": [], - "generatedAt": "2026-10-31T09:00:10.9561954\u002B00:00", + "generatedAt": "2026-11-02T14:19:11.1813060\u002B00:00", "generatedFiles": [ "TurnOnProducer.cs", "IReceiveLightMeasurementHandler.cs", @@ -26,7 +26,7 @@ "Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includeChannels": [], "mode": "both", "rootNamespace": "Streetlights.Client", diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/JsonDateTime.cs index f210d44f55b..2184a9ef0ef 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/JsonDateTime.cs @@ -377,6 +377,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs index 2da6fcb257f..fda97c59df6 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public LightIntensityMeasuredInLumens Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.Mutable.cs b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.Mutable.cs index ecc02ce29e4..99e461f5a8a 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.Mutable.cs +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.cs b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.cs index fc8fafba442..d6f2eee01a2 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.cs +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/LightMeasuredPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public LightMeasuredPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.Mutable.cs b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.Mutable.cs index 1827fc0dec4..a37276a0587 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.Mutable.cs +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs index c02bcd2be89..334adefce53 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WhetherToTurnOnOrOffTheLight Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.cs b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.cs index 2aab06bcdb2..dcd71eb170a 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.cs +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/Models/TurnOnOffPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public TurnOnOffPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/corvusjson-asyncapi.lock b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/corvusjson-asyncapi.lock index 18c445c458a..55aa02ea3f0 100644 --- a/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/corvusjson-asyncapi.lock +++ b/docs/ExampleRecipes/038-AsyncApiEndToEnd/Generated/corvusjson-asyncapi.lock @@ -1,6 +1,6 @@ { "excludeChannels": [], - "generatedAt": "2026-10-31T09:00:11.8634259\u002B00:00", + "generatedAt": "2026-11-02T14:19:12.4458265\u002B00:00", "generatedFiles": [ "TurnOnProducer.cs", "IReceiveLightMeasurementHandler.cs", @@ -26,7 +26,7 @@ "Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includeChannels": [], "mode": "both", "rootNamespace": "Streetlights.Client", diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/JsonDateTime.cs b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/JsonDateTime.cs index f210d44f55b..2184a9ef0ef 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/JsonDateTime.cs +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/JsonDateTime.cs @@ -377,6 +377,12 @@ private void CheckValidInstance() public JsonDateTime Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs index 2da6fcb257f..fda97c59df6 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.LightIntensityMeasuredInLumens.cs @@ -402,6 +402,12 @@ private void CheckValidInstance() public LightIntensityMeasuredInLumens Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.Mutable.cs b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.Mutable.cs index ecc02ce29e4..99e461f5a8a 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.Mutable.cs +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.cs b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.cs index fc8fafba442..d6f2eee01a2 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.cs +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/LightMeasuredPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public LightMeasuredPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.Mutable.cs b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.Mutable.cs index 1827fc0dec4..a37276a0587 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.Mutable.cs +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.Mutable.cs @@ -341,6 +341,31 @@ public bool RemoveSentAt() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs index c02bcd2be89..334adefce53 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.cs @@ -318,6 +318,12 @@ private void CheckValidInstance() public WhetherToTurnOnOrOffTheLight Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.cs b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.cs index 2aab06bcdb2..dcd71eb170a 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.cs +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/Models/TurnOnOffPayload.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public TurnOnOffPayload Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/corvusjson-asyncapi.lock b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/corvusjson-asyncapi.lock index 764b437013b..d2e34227cee 100644 --- a/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/corvusjson-asyncapi.lock +++ b/docs/ExampleRecipes/039-AsyncApiAuthentication/Generated/corvusjson-asyncapi.lock @@ -1,6 +1,6 @@ { "excludeChannels": [], - "generatedAt": "2026-10-31T09:00:12.8006487\u002B00:00", + "generatedAt": "2026-11-02T14:19:13.6399387\u002B00:00", "generatedFiles": [ "TurnOnProducer.cs", "IReceiveLightMeasurementHandler.cs", @@ -26,7 +26,7 @@ "Models/TurnOnOffPayload.WhetherToTurnOnOrOffTheLight.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includeChannels": [], "mode": "both", "rootNamespace": "Streetlights.Client", diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.Mutable.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.Mutable.cs index 333cc68a333..8d4514df9ba 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.Mutable.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.Mutable.cs @@ -313,6 +313,31 @@ public void SetMessage(scoped in Petstore.V2.Client.Models.JsonString.Source val _documentVersion = _parent.Version; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.cs index 1d5474ad42e..f6c8ea513fd 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Error.cs @@ -378,6 +378,12 @@ private void CheckValidInstance() public Error Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsLimit.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsLimit.cs index 87624de5d03..011206c4f83 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsLimit.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsLimit.cs @@ -348,6 +348,12 @@ private void CheckValidInstance() public GetPetsLimit Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsTags.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsTags.cs index f5eb333ee52..01d9934c94a 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsTags.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/GetPetsTags.cs @@ -23,11 +23,13 @@ namespace Petstore.V2.Client.Models; public readonly partial struct GetPetsTags #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -77,6 +79,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -290,6 +307,12 @@ private void CheckValidInstance() public GetPetsTags Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt32.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt32.cs index 627df15672c..22581ca2724 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt32.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt32.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt32 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt64.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt64.cs index c8a42a5edcc..edac800ba89 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt64.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonInt64.cs @@ -343,6 +343,12 @@ private void CheckValidInstance() public JsonInt64 Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonString.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonString.cs index f0c977fe568..0e3765f6f3d 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonString.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/JsonString.cs @@ -310,6 +310,12 @@ private void CheckValidInstance() public JsonString Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.Mutable.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.Mutable.cs index f40e7b65e09..92331ab38ea 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.Mutable.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.Mutable.cs @@ -322,6 +322,31 @@ public bool RemoveTag() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.cs index 45e7919deda..86a6f79f19c 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/NewPet.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public NewPet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.Mutable.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.Mutable.cs index db3229b958b..6354ef9ec53 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.Mutable.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.Mutable.cs @@ -374,6 +374,31 @@ public bool RemoveTag() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.cs index 1ede0332699..7bfa6fa9e09 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pet.cs @@ -394,6 +394,12 @@ private void CheckValidInstance() public Pet Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pets.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pets.cs index a82cb5cf8bd..4e0b101523e 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pets.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/Pets.cs @@ -18,11 +18,13 @@ namespace Petstore.V2.Client.Models; public readonly partial struct Pets #if NET8_0_OR_GREATER : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable, ISpanFormattable, IUtf8SpanFormattable #else : IJsonElement, + global::System.Collections.Generic.IReadOnlyCollection, IFormattable #endif { @@ -72,6 +74,21 @@ public int GetArrayLength() return EnumeratorCreator.CreateArrayEnumerator(_parent, _idx); } + /// + /// Gets an enumerator over the items of the array, for foreach. It does not allocate. + /// + /// The enumerator. + public ArrayEnumerator GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray(); + + /// + int global::System.Collections.Generic.IReadOnlyCollection.Count => GetArrayLength(); + /// public JsonValueKind ValueKind => TokenType.ToValueKind(); @@ -285,6 +302,12 @@ private void CheckValidInstance() public Pets Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.Mutable.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.Mutable.cs index ddad3d35559..aa1ab42be64 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.Mutable.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.Mutable.cs @@ -322,6 +322,31 @@ public bool RemoveStatus() return result; } + /// + /// Adds to the document each property that is absent and has a default in the schema, with that default + /// as its value, and then does the same inside each property whose own type has properties. + /// + /// + /// + /// This changes the data. Reading an absent property already gives its default without it; this method writes + /// the defaults into the document as additional properties, so that they are there when the document is sent + /// to a system that does not apply the schema's defaults itself. + /// + /// + /// A property that is present keeps its value. Does nothing when the value is not an object. The items of + /// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written + /// as it is. + /// + /// + public void ApplyDefaults() + { + CheckValidInstance(); + if (ValueKind != JsonValueKind.Object) + { + return; + } + } + /// public void WriteTo(Utf8JsonWriter writer) { diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.StatusEntity.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.StatusEntity.cs index c749e71bc6b..3a366738605 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.StatusEntity.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.StatusEntity.cs @@ -313,6 +313,12 @@ private void CheckValidInstance() public StatusEntity Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.cs b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.cs index 1346b8db19b..876a6818cec 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.cs +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/Models/UpdatePetWithFormFormBody.cs @@ -373,6 +373,12 @@ private void CheckValidInstance() public UpdatePetWithFormFormBody Clone() { CheckValidInstance(); + if (!_parent.IsDisposable) + { + // Already a clone, or backed by a document that is never disposed. + return this; + } + return _parent.CloneElement(_idx); } diff --git a/docs/ExampleRecipes/042-OpenApi20Client/Generated/corvusjson-openapi.lock b/docs/ExampleRecipes/042-OpenApi20Client/Generated/corvusjson-openapi.lock index 236f855d7f8..7d7805ab8b4 100644 --- a/docs/ExampleRecipes/042-OpenApi20Client/Generated/corvusjson-openapi.lock +++ b/docs/ExampleRecipes/042-OpenApi20Client/Generated/corvusjson-openapi.lock @@ -1,6 +1,6 @@ { "excludePaths": [], - "generatedAt": "2026-10-31T09:00:15.5223673\u002B00:00", + "generatedAt": "2026-11-02T14:19:14.8531161\u002B00:00", "generatedFiles": [ "ListPetsRequest.cs", "ListPetsResponse.cs", @@ -47,7 +47,7 @@ "Models/UpdatePetWithFormFormBody.StatusEntity.JsonSchema.cs", "Models/CorvusJsonSchemaProgram.cs" ], - "generatorVersion": "1.0.0\u002B7b34359f0fa95ecd5d37f23490daaa9a0c913a63", + "generatorVersion": "1.0.0\u002B02df2404c37dc719afab3e9c70ade02ebafa22d5", "includePaths": [], "rootNamespace": "Petstore.V2.Client", "specFileHash": "10cc3488325cfb61d4a68bc721ede20dcd9b93cb9533a03071189478971208ca", diff --git a/docs/JsonPatch.md b/docs/JsonPatch.md index 4b4d76c30b4..ee8018f33c7 100644 --- a/docs/JsonPatch.md +++ b/docs/JsonPatch.md @@ -86,6 +86,19 @@ bool success = root.TryApplyPatch(patch); > **Note:** If an operation fails partway through, earlier operations in the patch will already have been applied. The document is left in a partially-patched state. If you need atomic all-or-nothing semantics, take a snapshot before applying (see [JsonDocumentBuilder](JsonDocumentBuilder.md) for snapshot/restore). +### Patching a generated type + +`TryApplyPatch` and `TryValidateAndApplyPatch` also take the mutable element of a generated type. The element refers to the patched value afterwards, even when the patch replaces the root: + +```csharp +using JsonDocumentBuilder builder = person.CreateBuilder(workspace); +Person.Mutable root = builder.RootElement; + +bool success = root.TryValidateAndApplyPatch(parsedPatch); +``` + +The result is not validated against the type's schema. Call `EvaluateSchema()` on it for that. + ## Building Patches with PatchBuilder The `PatchBuilder` provides a fluent API for constructing patch documents programmatically. Create one by calling `BeginPatch(workspace)` on any mutable element, chain operations, then call `GetPatchAndDispose()` to finalize: diff --git a/docs/OtherLanguages.md b/docs/OtherLanguages.md index dfc2c08727c..90c371ab2b4 100644 --- a/docs/OtherLanguages.md +++ b/docs/OtherLanguages.md @@ -33,7 +33,9 @@ PHP, R and Perl. plans to Go, with no native code, and the Julia package, the Object Pascal package and the OCaml package are each a port of the Go module. - **The same results.** Every implementation evaluates drafts 4, 6, 7, 2019-09 and 2020-12, passes the - JSON-Schema-Test-Suite, and reports results at the Basic, Detailed and Verbose levels, with the same rows (evaluation + JSON-Schema-Test-Suite (the .NET evaluators ignore its 73 leap-second cases, whose times the shared Corvus date and + time parsers refuse; see [Conformance](RuntimeEvaluator.md#conformance) for what each runner runs), and reports + results at the Basic, Detailed and Verbose levels, with the same rows (evaluation path, schema location, instance location and message, in the same order). Annotations come grouped the same way everywhere: instance location, then keyword, then schema location, then value (in R, as the columns of a data frame). Results from any of them can be consumed the same way. diff --git a/docs/PatternConformance.md b/docs/PatternConformance.md index ed4f0243edf..6fb0a11673f 100644 --- a/docs/PatternConformance.md +++ b/docs/PatternConformance.md @@ -17,14 +17,15 @@ refuses, how each limits a match, and where a port still differs from ECMA-262. error unless the two groups are in separate alternatives. `\p{WSpace}` is not a property name ECMA-262 lists. `Katakana_Or_Hiragana` is a Script value that no character has. The properties are those of Unicode 17. - **Limits.** A schema and an instance can both come from outside, so a pattern has limits of size, refused as too - large when the schema is compiled and never as not valid, and a match has a limit of time, 1 second by default. + large when the schema is compiled and never as not valid, and a match has a limit of time, 1 second by default (in + .NET generated code, the limit the generator is given). ## The ports | Port | How a pattern is matched | What is refused that is valid ECMA-262 | The limit of a match | Match-limit hits on the dataset | |---|---|---|---|---| -| .NET (V5) | [Corvus.Regex.Ecma262](https://corvus-oss.org/Corvus.Regex.Ecma262/), its own ECMA-262 engine over UTF-8, and the evaluator's own matchers for a few shapes where they are faster. Generated code carries the library's compiled matchers. With `--regexEngine DotNet`, generated code holds .NET `Regex` through a translation from the parse tree | Nothing, apart from the library's limits of size | `RegexMatchTimeout`, 1 second, which throws .NET's `RegexMatchTimeoutException`, and the library's cap on backtracking memory | 0 | -| .NET (V4 generated code) | Corvus.Regex.Ecma262's compiled matchers, as V5 generated code. With `--regexEngine DotNet`, .NET `Regex` through the same translation | Nothing, apart from the limits of size | A match timeout of 1 second in the generated code, which throws .NET's `RegexMatchTimeoutException` | 0 | +| .NET (V5) | [Corvus.Regex.Ecma262](https://corvus-oss.org/Corvus.Regex.Ecma262/), its own ECMA-262 engine over UTF-8, and the evaluator's own matchers for a few shapes where they are faster. Generated code carries the library's compiled matchers. With `--regexEngine DotNet`, generated code holds .NET `Regex` through a translation from the parse tree | Nothing, apart from the library's limits of size | `RegexMatchTimeout`, 1 second by default, which throws .NET's `RegexMatchTimeoutException`, and the library's cap on backtracking memory. Generated code takes the limit the generator is given (`--regexMatchTimeout`, `CorvusTextJsonRegexMatchTimeout`), or none (-1) | 0 | +| .NET (V4 generated code) | Corvus.Regex.Ecma262's compiled matchers, as V5 generated code. With `--regexEngine DotNet`, .NET `Regex` through the same translation | Nothing, apart from the limits of size | A match timeout of 1 second by default in the generated code, which throws .NET's `RegexMatchTimeoutException`. The generator sets another (`--regexMatchTimeout`, `CorvusJsonSchemaRegexMatchTimeout`), or none (-1) | 0 | | Rust, and the C library, C++, Python (Rust-backed), Ruby, PHP, R, Swift, Fortran and Perl (XS) built on it | Its own ECMA-262 engine, and the `regex` crate for patterns it proves linear | Nothing, apart from the limits of size | 1 second, as an error | 0 | | Go | Its own ECMA-262 engine, and the standard library's `regexp` for patterns it proves linear | Nothing, apart from the limits of size | 1 second, as an error | 0 | | Object Pascal | Its own ECMA-262 engine | Nothing, apart from the limits of size | 1 second, as an exception | 0 | @@ -52,13 +53,19 @@ answers. Each is a decision recorded here, with an issue where there is work to - **Draft 2019-09 and draft 2020-12 read the grammar of ECMAScript 2020,** the edition they cite, so a modifier group such as `(?i:a)` or a duplicate group name is refused under them, as today's grammar accepts it under the other dialects. `RegexEdition` (and the generators' `--regexEdition`) chooses another. -- **A JSON string with a lone surrogate throws.** The parser accepts an instance string that holds the escape of half - of a surrogate pair, such as `"\ud800"`, and `pattern`, `minLength` and `maxLength` then throw - `InvalidOperationException` (in V4 generated code too). Every other port refuses such a document when it parses - it, or reports it as not valid. The 46,438 texts of the dataset's `lone-surrogates.jsonl` all throw +- **A string that is not well-formed text is not valid against a keyword that reads it.** The parser accepts an + instance string that holds the escape of half of a surrogate pair, such as `"\ud800"`, or bytes that are not + UTF-8. Such text is checked only when a keyword reads it. A keyword that reads its characters (`pattern`, + `minLength`, `maxLength`, an asserted `format` or `contentMediaType`, and the same keywords applied to a property's + name) reports it as not valid, so a lone surrogate never matches a pattern. A keyword that compares it (`const`, + `enum`, `uniqueItems`, and the names of `properties`) finds it equal only to the same text. Nothing throws. Text + the parser found all ASCII is not checked again, and other text is checked once by a keyword that reads its + characters. Most other ports refuse such a document when they parse it. Of the 68,770 texts of the dataset's + `lone-surrogates.jsonl`, none throws, and the 11,517 that V8 matches are reported as not valid, where the ports + that refuse them at parse give no answer (run on 2026-11-02). In V4 generated code, a keyword that reads such a + string reports the value as not valid too, and a keyword that looks up a property by name can report an object + with such a name as not valid, because System.Text.Json unescapes the names it compares ([#1021](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021)). -- **`idn-email` has a limit of 320 bytes on the whole address.** The Rust crate has no limit on the address as a - whole. The host name of the address has the limit of 253 characters as A-labels in both ([#1029](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1029)). - **.NET Framework and a large count, with the DotNet engine.** .NET Framework's `Regex` makes a string of the count of a repetition of one character when it is constructed, so `^a{100000000}$` costs some 200 MB there, and a count no string can reach is written as a part that never matches. .NET does neither, and nor does Corvus.Regex.Ecma262. @@ -97,5 +104,5 @@ answers. Each is a decision recorded here, with an issue where there is work to - **No limit of a match.** A `RegExp` match cannot be interrupted, so a pattern that backtracks without end, on a text made for it, does not return. The answers are those of the host engine, which are V8's on Node and in Chrome. - A port of the ECMA-262 engine, which would give a limit and the same answers on every host, is to follow - ([#1026](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1026)). \ No newline at end of file + This is a decision: `pattern` and `patternProperties` stay with the host's `RegExp`, and a port of the ECMA-262 + engine to TypeScript is not planned ([#1026](https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1026)). \ No newline at end of file diff --git a/docs/RuntimeEvaluator.md b/docs/RuntimeEvaluator.md index 5df7244f9c2..5e41e94604f 100644 --- a/docs/RuntimeEvaluator.md +++ b/docs/RuntimeEvaluator.md @@ -83,10 +83,20 @@ results into `IJsonSchemaResultsCollector` with evaluation path, schema location `tests/.../Suite/JsonSchemaTestSuiteTests.cs` runs every file under `tests/draft4`, `draft6`, `draft7`, `draft2019-09`, `draft2020-12` (required, `optional/` and `optional/format/` with format assertion on). -The only exclusions are `draft4/optional/zeroTerminatedFloats.json` and the leap-second cases in the -`time`/`date-time` format files, matching Corvus.JsonSchema. `AnnotationSuiteTests.cs` runs the annotation +No file is excluded, so it runs all 7,967 cases, `draft4/optional/zeroTerminatedFloats.json` among them. Failures +on the 73 leap-second cases in the `time`/`date-time` format files are ignored, because the shared Corvus date and +time parsers reject leap seconds (see [Known gaps and next steps](#known-gaps-and-next-steps)); 28 of those cases expect a leap second to be +accepted, and the other 45 expect an invalid one to be rejected. `AnnotationSuiteTests.cs` runs the annotation suite through a verbose collector and `JsonSchemaAnnotationProducer`. +The runners of the other evaluators differ: + +| Runner | Cases run | Files skipped | Failures ignored | +|---|---:|---|---| +| C# | 7,967 | none | the 73 leap-second cases | +| TypeScript | 7,966 | `draft4/optional/zeroTerminatedFloats.json` (`JSON.parse` reads `1.0` as `1`) | none | +| Rust | 7,966 | `draft4/optional/zeroTerminatedFloats.json` | none | + ## Flag-mode optimisations (after reading Blaze's compiler) | Technique | Where | Notes | diff --git a/docs/SourceGenerator.md b/docs/SourceGenerator.md index 22a2b90d497..dd67838bd44 100644 --- a/docs/SourceGenerator.md +++ b/docs/SourceGenerator.md @@ -159,6 +159,7 @@ Control the generator's behaviour with MSBuild properties in your `.csproj`: | `CorvusTextJsonRegexEngine` | `Ecma262` | The engine the generated regular expressions are written for. `Ecma262` writes [Corvus.Regex.Ecma262](https://corvus-oss.org/Corvus.Regex.Ecma262/)'s compiled matchers, with the compiled regular expression as data (once each, in `CorvusJsonSchemaRegularExpressions`), for the program and for pattern-property fields, which are that library's `Regex`; the generator compiles them into the program, so the evaluator compiles none at run time. `DotNet` writes .NET's `System.Text.RegularExpressions`, as earlier versions did. | | `CorvusTextJsonRegexEdition` | each dialect's | The edition of ECMA-262 whose grammar every pattern is read with: `Current` or `Es2020`. By default draft 2019-09 and draft 2020-12 read patterns with the grammar of ECMAScript 2020, which they cite, and the other dialects with today's. `Ecma262` only. | | `CorvusTextJsonRegexUnicodeVersion` | `Default` | The version of Unicode every pattern is read with: `Default` (V8's, 17), `13`, `17`, `18` or `Latest`. `Ecma262` only. | +| `CorvusTextJsonRegexMatchTimeout` | `1000` | The limit, in milliseconds, on one match of a regular expression in generated code, or `-1` for none. A match that runs for longer throws `RegexMatchTimeoutException`. A pattern proved to match in time proportional to the text has no limit whatever this says. Any other value is reported as an error of the generator. The V4 source generator's property is `CorvusJsonSchemaRegexMatchTimeout`. | | `CorvusTextJsonDisabledNamingHeuristics` | `DocumentationNameHeuristic` | Semicolon-separated list of specific naming heuristics to disable (e.g., `DocumentationNameHeuristic;PathNameHeuristic`). | | `CorvusTextJsonSuppressAnalyzerDiagnosticsInGeneratedCode` | `true` | When `true`, analyzer diagnostics located in the generated code are not reported (see [Analyzers and generated code](#analyzers-and-generated-code)). Compiler diagnostics are unaffected. Set to `false` to have them reported. | @@ -170,7 +171,7 @@ For each `[JsonSchemaTypeGenerator]` attribute, the generator produces a complet - **Type-safe property accessors** for every property defined in the schema - **Validation** via `EvaluateSchema()` with full draft 2020-12 (or earlier draft) support. A `pattern` whose match - runs for longer than 1 second throws `RegexMatchTimeoutException` (see + runs for longer than 1 second (or the limit `CorvusTextJsonRegexMatchTimeout` sets) throws `RegexMatchTimeoutException` (see [SchemaEvaluator.md](SchemaEvaluator.md#what-gets-generated)). A `pattern` or `patternProperties` pattern that is not a valid ECMA-262 regular expression is reported as an error of the generator (`CRV1001`) and nothing is generated for the schema (see [RuntimeEvaluator.md](RuntimeEvaluator.md#patterns)). A pattern over a limit of size diff --git a/docs/code-sample-catalog.yaml b/docs/code-sample-catalog.yaml index 02ac89ffe0c..a3a2c187bd5 100644 --- a/docs/code-sample-catalog.yaml +++ b/docs/code-sample-catalog.yaml @@ -795,17 +795,17 @@ main-docs: - {index: 1, language: bash, lines: [19, 22]} - {index: 2, language: bash, lines: [30, 34]} - {index: 3, language: bash, lines: [44, 46]} - - {index: 4, language: bash, lines: [81, 100]} - - {index: 5, language: bash, lines: [106, 108]} - - {index: 6, language: json, lines: [112, 148]} - - {index: 7, language: bash, lines: [212, 214]} - - {index: 8, language: bash, lines: [222, 224]} - - {index: 9, language: bash, lines: [230, 232]} - - {index: 10, language: json, lines: [264, 274]} - - {index: 11, language: ini, lines: [300, 307]} - - {index: 12, language: bash, lines: [340, 345]} - - {index: 13, language: json, lines: [365, 374]} - - {index: 14, language: bash, lines: [403, 415]} + - {index: 4, language: bash, lines: [82, 101]} + - {index: 5, language: bash, lines: [107, 109]} + - {index: 6, language: json, lines: [113, 149]} + - {index: 7, language: bash, lines: [213, 215]} + - {index: 8, language: bash, lines: [223, 225]} + - {index: 9, language: bash, lines: [231, 233]} + - {index: 10, language: json, lines: [265, 275]} + - {index: 11, language: ini, lines: [301, 308]} + - {index: 12, language: bash, lines: [341, 346]} + - {index: 13, language: json, lines: [366, 375]} + - {index: 14, language: bash, lines: [404, 416]} - path: "docs/CodeSampleCatalog.md" blocks: - {index: 0, language: powershell, lines: [13, 26]} @@ -820,11 +820,13 @@ main-docs: blocks: - {index: 0, language: csharp, lines: [22, 25], category: compilable, verified: false} - {index: 1, language: csharp, lines: [33, 35], category: compilable, verified: false} - - {index: 2, language: csharp, lines: [45, 50], category: compilable, verified: false} - - {index: 3, language: csharp, lines: [58, 65], category: compilable, verified: false} - - {index: 4, language: csharp, lines: [84, 89], category: compilable, verified: false} - - {index: 5, language: csharp, lines: [102, 105], category: compilable, verified: false} - - {index: 6, language: csharp, lines: [127, 134], category: compilable, verified: false} + - {index: 2, language: csharp, lines: [46, 54], category: compilable, verified: false} + - {index: 3, language: csharp, lines: [64, 69], category: compilable, verified: false} + - {index: 4, language: csharp, lines: [77, 84], category: compilable, verified: false} + - {index: 5, language: csharp, lines: [103, 108], category: compilable, verified: false} + - {index: 6, language: csharp, lines: [126, 132], category: compilable, verified: false} + - {index: 7, language: csharp, lines: [143, 146], category: compilable, verified: false} + - {index: 8, language: csharp, lines: [168, 175], category: compilable, verified: false} - path: "docs/CrossPlatformDynamicCompilation.md" blocks: - {index: 0, language: , lines: [56, 59]} @@ -851,9 +853,9 @@ main-docs: - {index: 13, language: , lines: [485, 488]} - path: "docs/EcmaRegexTranslator.md" blocks: - - {index: 0, language: csharp, lines: [50, 64], category: compilable, verified: false} - - {index: 1, language: csharp, lines: [71, 104], category: fragment, verified: false} - - {index: 2, language: powershell, lines: [237, 239]} + - {index: 0, language: csharp, lines: [61, 75], category: compilable, verified: false} + - {index: 1, language: csharp, lines: [82, 115], category: fragment, verified: false} + - {index: 2, language: powershell, lines: [247, 249]} - path: "docs/ImplementingNatsJetStreamAndAzureServiceBus.md" blocks: - {index: 0, language: , lines: [14, 33]} @@ -1060,22 +1062,23 @@ main-docs: - {index: 2, language: csharp, lines: [27, 51], category: compilable, verified: false} - {index: 3, language: csharp, lines: [59, 70], category: compilable, verified: false} - {index: 4, language: csharp, lines: [76, 83], category: compilable, verified: false} - - {index: 5, language: csharp, lines: [93, 100], category: compilable, verified: false} - - {index: 6, language: csharp, lines: [106, 117], category: fragment, verified: false} - - {index: 7, language: csharp, lines: [127, 136], category: compilable, verified: false} - - {index: 8, language: csharp, lines: [140, 143], category: compilable, verified: false} - - {index: 9, language: csharp, lines: [149, 154], category: compilable, verified: false} - - {index: 10, language: csharp, lines: [162, 165], category: compilable, verified: false} - - {index: 11, language: csharp, lines: [171, 177], category: compilable, verified: false} - - {index: 12, language: csharp, lines: [185, 191], category: compilable, verified: false} - - {index: 13, language: csharp, lines: [197, 202], category: compilable, verified: false} - - {index: 14, language: csharp, lines: [206, 215], category: compilable, verified: false} - - {index: 15, language: csharp, lines: [271, 288], category: compilable, verified: false} - - {index: 16, language: csharp, lines: [321, 344], category: compilable, verified: false} - - {index: 17, language: csharp, lines: [358, 361], category: fragment, verified: false} - - {index: 18, language: csharp, lines: [365, 369], category: fragment, verified: false} - - {index: 19, language: csharp, lines: [373, 376], category: fragment, verified: false} - - {index: 20, language: csharp, lines: [382, 385], category: compilable, verified: false} + - {index: 5, language: csharp, lines: [93, 98], category: compilable, verified: false} + - {index: 6, language: csharp, lines: [106, 113], category: fragment, verified: false} + - {index: 7, language: csharp, lines: [119, 130], category: compilable, verified: false} + - {index: 8, language: csharp, lines: [140, 149], category: compilable, verified: false} + - {index: 9, language: csharp, lines: [153, 156], category: compilable, verified: false} + - {index: 10, language: csharp, lines: [162, 167], category: compilable, verified: false} + - {index: 11, language: csharp, lines: [175, 178], category: compilable, verified: false} + - {index: 12, language: csharp, lines: [184, 190], category: compilable, verified: false} + - {index: 13, language: csharp, lines: [198, 204], category: compilable, verified: false} + - {index: 14, language: csharp, lines: [210, 215], category: compilable, verified: false} + - {index: 15, language: csharp, lines: [219, 228], category: compilable, verified: false} + - {index: 16, language: csharp, lines: [284, 301], category: compilable, verified: false} + - {index: 17, language: csharp, lines: [334, 357], category: fragment, verified: false} + - {index: 18, language: csharp, lines: [371, 374], category: fragment, verified: false} + - {index: 19, language: csharp, lines: [378, 382], category: fragment, verified: false} + - {index: 20, language: csharp, lines: [386, 389], category: compilable, verified: false} + - {index: 21, language: csharp, lines: [395, 398], category: compilable, verified: false} - path: "docs/JsonPath.md" blocks: - {index: 0, language: bash, lines: [51, 54]} @@ -1537,9 +1540,9 @@ main-docs: - {index: 29, language: powershell, lines: [415, 421]} - path: "docs/RuntimeEvaluator.md" blocks: - - {index: 0, language: csharp, lines: [271, 289], category: compilable, verified: false} - - {index: 1, language: csharp, lines: [339, 351], category: compilable, verified: false} - - {index: 2, language: xml, lines: [438, 442]} + - {index: 0, language: csharp, lines: [281, 299], category: compilable, verified: false} + - {index: 1, language: csharp, lines: [349, 361], category: compilable, verified: false} + - {index: 2, language: xml, lines: [448, 452]} - path: "docs/SchemaEvaluator.md" blocks: - {index: 0, language: xml, lines: [19, 26]} @@ -1561,10 +1564,10 @@ main-docs: - {index: 7, language: xml, lines: [114, 123]} - {index: 8, language: xml, lines: [127, 131]} - {index: 9, language: xml, lines: [139, 146]} - - {index: 10, language: xml, lines: [194, 198]} - - {index: 11, language: , lines: [202, 207]} - - {index: 12, language: ini, lines: [226, 233]} - - {index: 13, language: ini, lines: [235, 242]} + - {index: 10, language: xml, lines: [195, 199]} + - {index: 11, language: , lines: [203, 208]} + - {index: 12, language: ini, lines: [227, 234]} + - {index: 13, language: ini, lines: [236, 243]} - path: "docs/StandaloneEvaluatorInternals.md" blocks: - {index: 0, language: csharp, lines: [66, 73], category: compilable, verified: false} diff --git a/src-rs/corvus-json-schema/README.md b/src-rs/corvus-json-schema/README.md index 6a08ee51a96..a53bc3496e2 100644 --- a/src-rs/corvus-json-schema/README.md +++ b/src-rs/corvus-json-schema/README.md @@ -183,9 +183,9 @@ cargo test This runs: - **`tests/suite.rs`:** the full [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite) from the repository's submodule, covering required and optional tests plus `optional/format` with format asserted. - Every case runs fail-fast and through a collector at each level, and the verdicts must agree. Exclusions match the - C# runner: `draft4/optional/zeroTerminatedFloats.json` and leap seconds in the format run. Use `SUITE_DRAFT` and - `SUITE_FILTER` to narrow the run. + Every case runs fail-fast and through a collector at each level, and the verdicts must agree. The one exclusion is + `draft4/optional/zeroTerminatedFloats.json`, and no failure is ignored: the 7,966 other cases all pass, the + leap-second cases of the format run among them. Use `SUITE_DRAFT` and `SUITE_FILTER` to narrow the run. - **`tests/annotations.rs`:** the suite's annotation tests. - **`tests/results.rs`:** the results-collection expectations shared with the C# and TypeScript evaluators. - **`tests/metaschemas.rs`:** checks that `src/metaschemas.rs` matches `src/Corvus.Text.Json/metaschema`. diff --git a/src-rs/corvus-json-schema/tests/suite.rs b/src-rs/corvus-json-schema/tests/suite.rs index 6899e854536..93e6041f2e6 100644 --- a/src-rs/corvus-json-schema/tests/suite.rs +++ b/src-rs/corvus-json-schema/tests/suite.rs @@ -128,10 +128,6 @@ impl Runner { .unwrap_or_else(|_| Err("panic during evaluation".into())), }; if actual.as_ref() != Ok(&expected) { - // Leap seconds are skipped in the format run, as in the C# runner. - if assert_format && test_description.to_lowercase().contains("leap second") { - continue; - } file_failed += 1; self.failures.push(format!( "{label} [{description}] {test_description}: expected {expected}, got {}", diff --git a/src-ts/corvus-json-schema/README.md b/src-ts/corvus-json-schema/README.md index 1429327ffd8..7b1aaadffff 100644 --- a/src-ts/corvus-json-schema/README.md +++ b/src-ts/corvus-json-schema/README.md @@ -6,8 +6,8 @@ Corvus.Text.Json V5 standalone evaluator (`Corvus.Text.Json.RuntimeEvaluator`, s validates parsed JSON values (`JSON.parse` output) against it. - **Conformant**: passes all 7,966 tests of the JSON-Schema-Test-Suite (required, optional and `optional/format`, - every draft), with the same single exclusion as the C# runner (`draft4/optional/zeroTerminatedFloats.json`, which - `JSON.parse` cannot express). + every draft), with one exclusion (`draft4/optional/zeroTerminatedFloats.json`, whose `1.0` `JSON.parse` reads as + `1`) and no failure ignored. - **Fast**: see [Performance](#performance). - **Results and annotations**: evaluate with a results collector at the Basic, Detailed or Verbose level for the same rows (locations, messages, order) as the C# `JsonSchemaResultsCollector`, and annotations as diff --git a/src-ts/corvus-json-schema/test/suite.mjs b/src-ts/corvus-json-schema/test/suite.mjs index 89db835be65..527e0453877 100644 --- a/src-ts/corvus-json-schema/test/suite.mjs +++ b/src-ts/corvus-json-schema/test/suite.mjs @@ -116,8 +116,6 @@ async function runFile(draft, file, label, assertFormat) { } } if (error !== undefined || actual !== test.valid) { - // Leap seconds are skipped in the format run, as in the C# runner. - if (assertFormat && /leap second/i.test(test.description)) continue; fileFailed++; failures.push(`${label} [${group.description}] ${test.description}: expected ${test.valid}, got ${error ? `${error.name}: ${error.message}` : actual}`); if (verbose && validate) failures.push(validate.source); diff --git a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/CSharpLanguageProvider.cs b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/CSharpLanguageProvider.cs index 955c4deb996..a5f11624378 100644 --- a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/CSharpLanguageProvider.cs +++ b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/CSharpLanguageProvider.cs @@ -30,6 +30,9 @@ public class CSharpLanguageProvider(CSharpLanguageProvider.Options? options = nu /// Gets the namespace of the generation's own files, such as its shared regular expressions. internal string DefaultNamespace => this.options.DefaultNamespace; + /// Gets the limit, in milliseconds, on one match of a regular expression of the generated code, or -1 for none. + internal int RegexMatchTimeoutMilliseconds => this.options.RegexMatchTimeoutMilliseconds; + /// /// Gets a instance with the default configuration and specified options. /// @@ -673,6 +676,7 @@ public readonly struct Namespace(JsonReference baseUri, string dotnetNamespace) /// The engine the regular expressions of generated code are written for (see ). Defaults to . /// The edition of the grammar every pattern is read with, or (the default) for the dialect's: ECMAScript 2020 for draft 2019-09 and draft 2020-12, today's for the others. For only. /// The version of Unicode every pattern is read with. For only. + /// The limit, in milliseconds, on one match of a regular expression of generated code, or -1 for none. Defaults to 1,000 (1 second). public class Options( string defaultNamespace, NamedType[]? namedTypes = null, @@ -690,7 +694,8 @@ public class Options( IReadOnlyDictionary? formatModeOverrides = null, GeneratedRegexEngine regexEngine = GeneratedRegexEngine.Ecma262, GeneratedRegexEdition? regexEdition = null, - GeneratedRegexUnicodeVersion regexUnicodeVersion = GeneratedRegexUnicodeVersion.Default) + GeneratedRegexUnicodeVersion regexUnicodeVersion = GeneratedRegexUnicodeVersion.Default, + int regexMatchTimeoutMilliseconds = ValidationCodeGeneratorExtensions.DefaultRegexMatchTimeoutMilliseconds) { private readonly FrozenDictionary namedTypeMap = namedTypes?.ToFrozenDictionary(kvp => kvp.Reference, kvp => kvp) ?? FrozenDictionary.Empty; private readonly FrozenDictionary namespaceMap = namespaces?.ToFrozenDictionary(kvp => kvp.BaseUri, kvp => kvp.DotnetNamespace) ?? FrozenDictionary.Empty; @@ -780,6 +785,11 @@ public class Options( /// Gets the version of Unicode every pattern is read with. internal GeneratedRegexUnicodeVersion RegexUnicodeVersion { get; } = regexUnicodeVersion; + /// Gets the limit, in milliseconds, on one match of a regular expression of generated code, or -1 for none. + internal int RegexMatchTimeoutMilliseconds { get; } = regexMatchTimeoutMilliseconds == System.Threading.Timeout.Infinite || regexMatchTimeoutMilliseconds > 0 + ? regexMatchTimeoutMilliseconds + : throw new ArgumentOutOfRangeException(nameof(regexMatchTimeoutMilliseconds), regexMatchTimeoutMilliseconds, "The match timeout is a positive number of milliseconds, or -1 for none."); + /// /// Try to get the namespace for the base URI. /// diff --git a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/SharedRegularExpressions.cs b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/SharedRegularExpressions.cs index 45a72cc5e91..ce6d66e7ebc 100644 --- a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/SharedRegularExpressions.cs +++ b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/SharedRegularExpressions.cs @@ -33,11 +33,14 @@ internal sealed class SharedRegularExpressions private readonly List<(string Name, string Pattern, bool Unicode, GeneratedRegexEdition Edition, GeneratedRegexUnicodeVersion UnicodeVersion)> entries = []; private readonly object sync = new(); private readonly string classReference; + private readonly int matchTimeoutMilliseconds; /// Initializes a new instance of the class. /// The namespace the class is written in (the generation's default). - public SharedRegularExpressions(string defaultNamespace) + /// The limit, in milliseconds, on one match, or -1 for none. + public SharedRegularExpressions(string defaultNamespace, int matchTimeoutMilliseconds = ValidationCodeGeneratorExtensions.DefaultRegexMatchTimeoutMilliseconds) { + this.matchTimeoutMilliseconds = matchTimeoutMilliseconds; this.Namespace = defaultNamespace; this.classReference = defaultNamespace.Length == 0 ? "global::" + ClassName : "global::" + defaultNamespace + "." + ClassName; } @@ -45,9 +48,10 @@ public SharedRegularExpressions(string defaultNamespace) /// Gets the regular expressions of a generation, adding the set when it is the first asked for. /// The code generator of the generation. /// The namespace the class is written in. + /// The limit, in milliseconds, on one match, or -1 for none. /// The set. - public static SharedRegularExpressions For(CodeGenerator generator, string defaultNamespace) - => Generations.GetValue(generator, _ => new SharedRegularExpressions(defaultNamespace)); + public static SharedRegularExpressions For(CodeGenerator generator, string defaultNamespace, int matchTimeoutMilliseconds = ValidationCodeGeneratorExtensions.DefaultRegexMatchTimeoutMilliseconds) + => Generations.GetValue(generator, _ => new SharedRegularExpressions(defaultNamespace, matchTimeoutMilliseconds)); /// Gets the regular expressions of a generation, or when none was asked for. /// The code generator of the generation. @@ -128,7 +132,7 @@ public string Reference(string pattern, bool unicode, GeneratedRegexEdition edit if (!EcmaRegexEmitter.TryEmit( pattern, unicode ? EcmaRegexFlags.Unicode : EcmaRegexFlags.None, - ValidationCodeGeneratorExtensions.RegexMatchTimeoutMilliseconds, + this.matchTimeoutMilliseconds, (EcmaRegexEdition)(int)edition, (EcmaRegexUnicodeVersion)(int)unicodeVersion, holder, diff --git a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.Constants.cs b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.Constants.cs index cfb954b32af..b6ed5d61686 100644 --- a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.Constants.cs +++ b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.Constants.cs @@ -19,12 +19,13 @@ namespace Corvus.Json.CodeGeneration.CSharp; public static partial class ValidationCodeGeneratorExtensions { /// - /// The match timeout of every regular expression generated code holds, in milliseconds: 1 second. A match that + /// The default match timeout of every regular expression generated code holds, in milliseconds: 1 second + /// (CSharpLanguageProvider.Options sets another, or none, -1). A match that /// runs for longer throws to the caller. /// .NET's engine does not return from a match of some patterns, and takes time exponential in the length of the /// text for others. /// - internal const int RegexMatchTimeoutMilliseconds = 1_000; + internal const int DefaultRegexMatchTimeoutMilliseconds = 1_000; private static CodeGenerator AppendValidationConstantFields(this CodeGenerator generator, TypeDeclaration typeDeclaration) { @@ -389,7 +390,7 @@ private static CodeGenerator AppendRegexValidationField(this CodeGenerator gener : new InvalidOperationException($"The pattern '{value}' of the keyword '{keyword.Keyword}' is not a valid ECMA-262 regular expression. {error}"); } - string reference = SharedRegularExpressions.For(generator, ((CSharpLanguageProvider)generator.LanguageProvider).DefaultNamespace).Reference( + string reference = SharedRegularExpressions.For(generator, ((CSharpLanguageProvider)generator.LanguageProvider).DefaultNamespace, ((CSharpLanguageProvider)generator.LanguageProvider).RegexMatchTimeoutMilliseconds).Reference( value, flags == EcmaRegexFlags.Unicode, typeDeclaration.RegexEdition(), @@ -480,8 +481,14 @@ private static CodeGenerator AppendRegexValidationFactoryMethod(this CodeGenerat string memberName = generator.GetMethodNameInScope(keyword.Keyword, prefix: "Create", suffix: index?.ToString(System.Globalization.CultureInfo.InvariantCulture)); - // Every form carries the match timeout (see RegexMatchTimeoutMilliseconds). - string timeout = RegexMatchTimeoutMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture); + // Every form carries the generation's match timeout (1 second unless the options say otherwise, -1 for none). + int matchTimeout = ((CSharpLanguageProvider)generator.LanguageProvider).RegexMatchTimeoutMilliseconds; + string timeout = matchTimeout == System.Threading.Timeout.Infinite + ? "global::System.Threading.Timeout.Infinite" + : matchTimeout.ToString(System.Globalization.CultureInfo.InvariantCulture); + string constructedTimeout = matchTimeout == System.Threading.Timeout.Infinite + ? "global::System.Text.RegularExpressions.Regex.InfiniteMatchTimeout" + : "global::System.TimeSpan.FromMilliseconds(" + timeout + ")"; #if !BUILDING_SOURCE_GENERATOR if (translatedValue.StartsWith(EcmaRegexTranslator.InterpretedMarker, StringComparison.Ordinal)) @@ -495,9 +502,9 @@ private static CodeGenerator AppendRegexValidationFactoryMethod(this CodeGenerat .Append(SymbolDisplay.FormatLiteral(translatedValue, true)) .Append(", ") .Append(constructedOptions) - .Append(", global::System.TimeSpan.FromMilliseconds(") - .Append(timeout) - .AppendLine("));"); + .Append(", ") + .Append(constructedTimeout) + .AppendLine(");"); } #endif @@ -509,9 +516,9 @@ private static CodeGenerator AppendRegexValidationFactoryMethod(this CodeGenerat .AppendQuotedStringLiteral(translatedValue) .Append(", ") .Append(constructedOptions) - .Append(", global::System.TimeSpan.FromMilliseconds(") - .Append(timeout) - .AppendLine("));"); + .Append(", ") + .Append(constructedTimeout) + .AppendLine(");"); #else .AppendLine("#if NET8_0_OR_GREATER && !DYNAMIC_BUILD") .AppendIndent("[GeneratedRegex(") @@ -531,9 +538,9 @@ private static CodeGenerator AppendRegexValidationFactoryMethod(this CodeGenerat .AppendQuotedStringLiteral(translatedValue) .Append(", ") .Append(constructedOptions) - .Append(", global::System.TimeSpan.FromMilliseconds(") - .Append(timeout) - .AppendLine("));") + .Append(", ") + .Append(constructedTimeout) + .AppendLine(");") .AppendLine("#endif"); #endif } diff --git a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.cs b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.cs index 5ad86fc0e94..fbafdda3db5 100644 --- a/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.cs +++ b/src-v4/Corvus.Json.CodeGeneration.CSharp/Corvus.Json.CodeGeneration/CSharp/ValidationCodeGeneratorExtensions.cs @@ -624,6 +624,11 @@ public static CodeGenerator AppendValidateMethod(this CodeGenerator generator, T extendedWarn = false; } + generator + .AppendLineIndent("try") + .AppendLineIndent("{") + .PushIndent(); + FormatHandlerRegistry.Instance.FormatHandlers.AppendFormatAssertion( generator, extendedFormat, @@ -634,6 +639,11 @@ public static CodeGenerator AppendValidateMethod(this CodeGenerator generator, T returnFromMethod: false, includeType: true, warn: extendedWarn); + + generator + .PopIndent() + .AppendLineIndent("}") + .AppendCatchTextThatIsNotWellFormed(); break; } @@ -673,7 +683,13 @@ public static CodeGenerator AppendValidateMethod(this CodeGenerator generator, T .AppendRequiresJsonValueKind(typeDeclaration) .AppendValidationHandlerSetup(typeDeclaration) .AppendSeparatorLine() + .AppendLineIndent("try") + .AppendLineIndent("{") + .PushIndent() .AppendValidationHandlerMethodCalls(typeDeclaration) + .PopIndent() + .AppendLineIndent("}") + .AppendCatchTextThatIsNotWellFormed() .AppendSeparatorLine() .AppendBlockIndent( """ @@ -695,6 +711,25 @@ public static CodeGenerator AppendValidateMethod(this CodeGenerator generator, T return generator; } + /// + /// Append the catch that reports a value whose text is not well-formed (an escape of half of a surrogate pair, or + /// bytes that are not UTF-8) as not valid. The parser accepts such text, and reading it throws; the catch takes + /// the exception only when the value's own text is not well-formed, so any other exception is not hidden + /// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). + /// + /// The generator for the type. + /// A reference to the generator having completed the operation. + private static CodeGenerator AppendCatchTextThatIsNotWellFormed(this CodeGenerator generator) + { + return generator + .AppendLineIndent("catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this))") + .AppendLineIndent("{") + .PushIndent() + .AppendLineIndent("result = Corvus.Json.Validate.TextIsNotWellFormed(result, level);") + .PopIndent() + .AppendLineIndent("}"); + } + /// /// Append code if the type declaration is using the JsonValueKind. /// diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64Content.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64Content.Validate.cs index 9845a22b0ed..bbbe8f347db 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64Content.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64Content.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonBase64Content public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeBase64Content(this, result, level); + try + { + result = Corvus.Json.Validate.TypeBase64Content(this, result, level); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64ContentPre201909.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64ContentPre201909.Validate.cs index c1fa6cee200..387b0b5cc3e 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64ContentPre201909.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64ContentPre201909.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonBase64ContentPre201909 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeBase64Content(this, result, level, false); + try + { + result = Corvus.Json.Validate.TypeBase64Content(this, result, level, false); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64String.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64String.Validate.cs index 7b880b6daf5..b339ad5d121 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64String.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64String.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonBase64String public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeBase64String(this, result, level); + try + { + result = Corvus.Json.Validate.TypeBase64String(this, result, level); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64StringPre201909.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64StringPre201909.Validate.cs index ae84fdbfa01..64375e8cdc4 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64StringPre201909.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonBase64StringPre201909.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonBase64StringPre201909 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeBase64String(this, result, level, false); + try + { + result = Corvus.Json.Validate.TypeBase64String(this, result, level, false); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonByte.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonByte.Validate.cs index 56c290978c1..d15c84a7482 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonByte.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonByte.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonByte public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeByte(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeByte(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContent.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContent.Validate.cs index c24017a9f7b..772165b0f9f 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContent.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContent.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonContent public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeContent(this, result, level); + try + { + result = Corvus.Json.Validate.TypeContent(this, result, level); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContentPre201909.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContentPre201909.Validate.cs index c95f442618d..e8a43284d6b 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContentPre201909.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonContentPre201909.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonContentPre201909 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeContent(this, result, level, false); + try + { + result = Corvus.Json.Validate.TypeContent(this, result, level, false); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDate.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDate.Validate.cs index 23d0de04d8f..33b8fe0c2ad 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDate.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDate.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonDate public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeDate(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeDate(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDateTime.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDateTime.Validate.cs index 3afabb75ce7..cc9afee4452 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDateTime.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDateTime.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonDateTime public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeDateTime(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeDateTime(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDecimal.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDecimal.Validate.cs index eb9b1ebc27c..f90c2111692 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDecimal.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDecimal.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonDecimal public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeDecimal(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeDecimal(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDouble.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDouble.Validate.cs index 105921938be..e4c6c9121a3 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDouble.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDouble.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonDouble public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeDouble(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeDouble(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDuration.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDuration.Validate.cs index 20605e91dda..a08defd66b1 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDuration.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonDuration.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonDuration public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeDuration(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeDuration(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonEmail.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonEmail.Validate.cs index 6b697178c20..1ca74c78296 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonEmail.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonEmail.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonEmail public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeEmail(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeEmail(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHalf.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHalf.Validate.cs index ea8cfaa3ab8..49ef157b3b2 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHalf.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHalf.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonHalf public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeHalf(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeHalf(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHostname.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHostname.Validate.cs index 72ba436fbaa..6b9e5e37f6f 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHostname.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonHostname.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonHostname public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeHostname(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeHostname(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnEmail.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnEmail.Validate.cs index 332e65bf361..8a51e096e0d 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnEmail.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnEmail.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonIdnEmail public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeIdnEmail(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeIdnEmail(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnHostname.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnHostname.Validate.cs index a67eac32daf..b9567798c8e 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnHostname.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIdnHostname.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonIdnHostname public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeIdnHostName(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeIdnHostName(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt128.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt128.Validate.cs index d917794115f..d64dffd6f66 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt128.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt128.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonInt128 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeInt128(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeInt128(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt16.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt16.Validate.cs index 539cda02901..a71a6fdefbb 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt16.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt16.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonInt16 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeInt16(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeInt16(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt32.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt32.Validate.cs index 8359e67749c..748b75f6f86 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt32.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt32.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonInt32 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeInt32(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeInt32(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt64.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt64.Validate.cs index ee4acac62c7..32728a6cc37 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt64.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonInt64.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonInt64 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeInt64(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeInt64(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV4.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV4.Validate.cs index d73d3a6ebea..1d32e2ff748 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV4.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV4.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonIpV4 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeIpV4(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeIpV4(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV6.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV6.Validate.cs index e528a792279..6123012637d 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV6.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIpV6.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonIpV6 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeIpV6(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeIpV6(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIri.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIri.Validate.cs index 6b39d9ca9ce..82caec1ad68 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIri.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIri.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonIri public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeIri(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeIri(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIriReference.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIriReference.Validate.cs index c54e6a0d808..c20062fb24d 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIriReference.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonIriReference.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonIriReference public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeIriReference(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeIriReference(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonPointer.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonPointer.Validate.cs index c8bf76fd82a..a7338ad5b58 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonPointer.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonPointer.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonPointer public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypePointer(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypePointer(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRegex.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRegex.Validate.cs index 3745d30cc18..040e68f95ff 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRegex.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRegex.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonRegex public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeRegex(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeRegex(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRelativePointer.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRelativePointer.Validate.cs index 997062120d8..64ad48b4a9c 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRelativePointer.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonRelativePointer.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonRelativePointer public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeRelativePointer(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeRelativePointer(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSByte.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSByte.Validate.cs index 14a5bc6b181..79b3e364b5a 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSByte.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSByte.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonSByte public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeSByte(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeSByte(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSingle.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSingle.Validate.cs index 55c7fe303d7..cee6c702267 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSingle.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonSingle.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonSingle public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeSingle(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeSingle(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonTime.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonTime.Validate.cs index 75c5639c99b..d8c165cabd2 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonTime.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonTime.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonTime public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeTime(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeTime(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt128.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt128.Validate.cs index e2bddd7e6c7..bd94a271979 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt128.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt128.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUInt128 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUInt128(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUInt128(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt16.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt16.Validate.cs index 750c379d487..4b7c494fc59 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt16.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt16.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUInt16 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUInt16(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUInt16(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt32.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt32.Validate.cs index 2dc65d2a30f..c7f76c44552 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt32.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt32.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUInt32 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUInt32(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUInt32(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt64.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt64.Validate.cs index 4c38fde1c8b..1ea6b7400f9 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt64.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUInt64.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUInt64 public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUInt64(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUInt64(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUri.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUri.Validate.cs index 55eb2abcee2..34a997690e5 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUri.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUri.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUri public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUri(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUri(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriReference.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriReference.Validate.cs index 90742b1e9ca..f7eeff0f3c9 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriReference.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriReference.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUriReference public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUriReference(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUriReference(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriTemplate.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriTemplate.Validate.cs index 738e6e4da2d..49989c8f026 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriTemplate.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUriTemplate.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUriTemplate public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUriTemplate(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUriTemplate(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUuid.Validate.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUuid.Validate.cs index 65d68db1ae9..ad4af622a2a 100644 --- a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUuid.Validate.cs +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/GeneratedCoreTypes/JsonUuid.Validate.cs @@ -23,7 +23,14 @@ public readonly partial struct JsonUuid public ValidationContext Validate(in ValidationContext validationContext, ValidationLevel level = ValidationLevel.Flag) { ValidationContext result = validationContext; - result = Corvus.Json.Validate.TypeUuid(this, result, level, null, null); + try + { + result = Corvus.Json.Validate.TypeUuid(this, result, level, null, null); + } + catch (global::System.InvalidOperationException) when (Corvus.Json.Validate.IsNotWellFormedText(this)) + { + result = Corvus.Json.Validate.TextIsNotWellFormed(result, level); + } return result; } } diff --git a/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/Validate.WellFormedText.cs b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/Validate.WellFormedText.cs new file mode 100644 index 00000000000..2d106610b24 --- /dev/null +++ b/src-v4/Corvus.Json.ExtendedTypes/Corvus.Json/Validate.WellFormedText.cs @@ -0,0 +1,184 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using System.Text.Json; + +namespace Corvus.Json; + +/// +/// JsonSchema validation errors. +/// +public static partial class Validate +{ + private const string TextIsNotWellFormedMessage = "Validation - the value is not well-formed text: it has an escape of half of a surrogate pair with no other half, or bytes that are not UTF-8."; + + /// + /// Whether a value's text is not well-formed: a string, or the name of one of an object's properties, that has an + /// escape of half of a surrogate pair with no other half (such as \ud800), or bytes that are not UTF-8. + /// + /// The type of the value. + /// The value. + /// when the text of the value is not well-formed. + /// + /// + /// The parser accepts such text, and reading it throws . Generated + /// validation catches that exception only when this is of the value it is validating, and + /// reports the value not valid (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). + /// + /// + /// It reads the raw text of the value, and is meant for the path on which reading the value has already thrown. + /// + /// + public static bool IsNotWellFormedText(in T instance) + where T : struct, IJsonValue + { +#if BUILDING_SOURCE_GENERATOR + return false; +#else + if (!instance.HasJsonElementBacking) + { + return instance.ValueKind == JsonValueKind.String && instance.AsString.HasDotnetBacking && HasLoneSurrogate((string)instance.AsString); + } + + JsonElement element = instance.AsJsonElement; + switch (element.ValueKind) + { + case JsonValueKind.String: + ReadOnlySpan raw = System.Runtime.InteropServices.JsonMarshal.GetRawUtf8Value(element); + return !IsWellFormedJsonStringText(raw.Slice(1, raw.Length - 2)); + + case JsonValueKind.Object: + foreach (JsonProperty property in element.EnumerateObject()) + { + if (!IsWellFormedJsonStringText(System.Runtime.InteropServices.JsonMarshal.GetRawUtf8PropertyName(property))) + { + return true; + } + } + + return false; + + default: + return false; + } +#endif + } + + /// + /// Reports that a value's text is not well-formed (see ). + /// + /// The validation context. + /// The validation level. + /// The validation context, with the value not valid. + public static ValidationContext TextIsNotWellFormed(in ValidationContext validationContext, ValidationLevel level) + { + return level == ValidationLevel.Flag + ? validationContext.WithResult(isValid: false) + : validationContext.WithResult(isValid: false, TextIsNotWellFormedMessage); + } + +#if !BUILDING_SOURCE_GENERATOR + /// + /// Whether the raw text of a JSON string (between its quotes) is UTF-8 and every escape of a surrogate is one of a + /// pair. + /// + private static bool IsWellFormedJsonStringText(ReadOnlySpan raw) + { + if (!IsUtf8(raw)) + { + return false; + } + + bool expectLow = false; + for (int i = raw.IndexOf((byte)'\\'); i >= 0 && i < raw.Length; i++) + { + if (raw[i] != (byte)'\\') + { + if (expectLow) + { + return false; + } + + continue; + } + + if (raw[i + 1] != (byte)'u') + { + if (expectLow) + { + return false; + } + + i++; + continue; + } + + // The parser accepted the text, so a \u has four hex digits. + int codeUnit = 0; + for (int d = i + 2; d < i + 6; d++) + { + int b = raw[d] | 0x20; + codeUnit = (codeUnit << 4) + (b <= '9' ? b - '0' : b - 'a' + 10); + } + + i += 5; + bool high = codeUnit is >= 0xD800 and <= 0xDBFF; + bool low = codeUnit is >= 0xDC00 and <= 0xDFFF; + if (expectLow) + { + if (!low) + { + return false; + } + + expectLow = false; + } + else if (low) + { + return false; + } + else + { + expectLow = high; + } + } + + return !expectLow; + } + + private static bool IsUtf8(ReadOnlySpan text) + { +#if NET + return System.Text.Unicode.Utf8.IsValid(text); +#else + try + { + JsonReaderHelper.s_utf8Encoding.GetCharCount(text.ToArray()); + return true; + } + catch (System.Text.DecoderFallbackException) + { + return false; + } +#endif + } + + private static bool HasLoneSurrogate(string text) + { + for (int i = 0; i < text.Length; i++) + { + if (char.IsHighSurrogate(text[i]) && i + 1 < text.Length && char.IsLowSurrogate(text[i + 1])) + { + i++; + } + else if (char.IsSurrogate(text[i])) + { + return true; + } + } + + return false; + } +#endif +} \ No newline at end of file diff --git a/src-v4/Corvus.Json.SourceGenerator/Corvus.Json.SourceGenerator.props b/src-v4/Corvus.Json.SourceGenerator/Corvus.Json.SourceGenerator.props index 1f9bea9a9ce..d4c930fab3b 100644 --- a/src-v4/Corvus.Json.SourceGenerator/Corvus.Json.SourceGenerator.props +++ b/src-v4/Corvus.Json.SourceGenerator/Corvus.Json.SourceGenerator.props @@ -12,6 +12,7 @@ + diff --git a/src-v4/Corvus.Json.SourceGenerator/IncrementalSourceGenerator.cs b/src-v4/Corvus.Json.SourceGenerator/IncrementalSourceGenerator.cs index 298a70e3455..28fbd40e20f 100644 --- a/src-v4/Corvus.Json.SourceGenerator/IncrementalSourceGenerator.cs +++ b/src-v4/Corvus.Json.SourceGenerator/IncrementalSourceGenerator.cs @@ -154,7 +154,8 @@ private static void GenerateCode(SourceProductionContext context, TypesToGenerat : FormatAssertionModeParser.ParseSpecification(generationSource.FormatModeSpecification, ';', ','), regexEngine: generationSource.RegexEngine, regexEdition: generationSource.RegexEdition, - regexUnicodeVersion: generationSource.RegexUnicodeVersion); + regexUnicodeVersion: generationSource.RegexUnicodeVersion, + regexMatchTimeoutMilliseconds: generationSource.RegexMatchTimeoutMilliseconds); var languageProvider = CSharpLanguageProvider.DefaultWithOptions(options); @@ -373,6 +374,16 @@ private static GlobalOptions GetGlobalOptions(AnalyzerConfigOptionsProvider sour }; } + int regexMatchTimeoutMilliseconds = Corvus.Json.CodeGeneration.CSharp.ValidationCodeGeneratorExtensions.DefaultRegexMatchTimeoutMilliseconds; + if (source.GlobalOptions.TryGetValue("build_property.CorvusJsonSchemaRegexMatchTimeout", out string? regexMatchTimeoutName) && regexMatchTimeoutName.Length > 0) + { + if (!int.TryParse(regexMatchTimeoutName, System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.CultureInfo.InvariantCulture, out regexMatchTimeoutMilliseconds) || + (regexMatchTimeoutMilliseconds != -1 && regexMatchTimeoutMilliseconds <= 0)) + { + throw new InvalidOperationException($"Invalid build property value for 'CorvusJsonSchemaRegexMatchTimeout': '{regexMatchTimeoutName}'. Expected a positive number of milliseconds, or -1 for no limit."); + } + } + return new( fallbackVocabulary, optionalAsNullable, @@ -386,7 +397,8 @@ private static GlobalOptions GetGlobalOptions(AnalyzerConfigOptionsProvider sour formatModeSpecification, regexEngine, regexEdition, - regexUnicodeVersion); + regexUnicodeVersion, + regexMatchTimeoutMilliseconds); } private static CompoundDocumentResolver BuildDocumentResolver(ImmutableArray source, CancellationToken token) @@ -542,6 +554,8 @@ private readonly struct GenerationContext(CompoundDocumentResolver left, GlobalO public GeneratedRegexEdition? RegexEdition { get; } = right.RegexEdition; public GeneratedRegexUnicodeVersion RegexUnicodeVersion { get; } = right.RegexUnicodeVersion; + + public int RegexMatchTimeoutMilliseconds { get; } = right.RegexMatchTimeoutMilliseconds; } private readonly struct TypesToGenerate(ImmutableArray left, GenerationContext right) @@ -575,6 +589,8 @@ private readonly struct TypesToGenerate(ImmutableArray public GeneratedRegexEdition? RegexEdition { get; } = right.RegexEdition; public GeneratedRegexUnicodeVersion RegexUnicodeVersion { get; } = right.RegexUnicodeVersion; + + public int RegexMatchTimeoutMilliseconds { get; } = right.RegexMatchTimeoutMilliseconds; } private readonly struct GlobalOptions( @@ -590,7 +606,8 @@ private readonly struct GlobalOptions( string? formatModeSpecification, GeneratedRegexEngine regexEngine, GeneratedRegexEdition? regexEdition, - GeneratedRegexUnicodeVersion regexUnicodeVersion) + GeneratedRegexUnicodeVersion regexUnicodeVersion, + int regexMatchTimeoutMilliseconds) { public IVocabulary FallbackVocabulary { get; } = fallbackVocabulary; @@ -617,5 +634,7 @@ private readonly struct GlobalOptions( public GeneratedRegexEdition? RegexEdition { get; } = regexEdition; public GeneratedRegexUnicodeVersion RegexUnicodeVersion { get; } = regexUnicodeVersion; + + public int RegexMatchTimeoutMilliseconds { get; } = regexMatchTimeoutMilliseconds; } } \ No newline at end of file diff --git a/src-v4/Corvus.Json.SourceGeneratorTools.ForLanguageProvider/SourceGeneratorHelpers.cs b/src-v4/Corvus.Json.SourceGeneratorTools.ForLanguageProvider/SourceGeneratorHelpers.cs index 47207e655ca..42611a288cc 100644 --- a/src-v4/Corvus.Json.SourceGeneratorTools.ForLanguageProvider/SourceGeneratorHelpers.cs +++ b/src-v4/Corvus.Json.SourceGeneratorTools.ForLanguageProvider/SourceGeneratorHelpers.cs @@ -145,7 +145,7 @@ public static List GenerateCode(SourceProductio { if (!context.CancellationToken.IsCancellationRequested) { - context.AddSource(codeFile.FileName, SourceText.From(codeFile.FileContent, Encoding.UTF8)); + context.AddSource(GetHintName(codeFile.FileName, defaultNamespace), SourceText.From(codeFile.FileContent, Encoding.UTF8)); } } @@ -315,4 +315,40 @@ public readonly struct GenerationContext(IDocumentResolver resol /// public TGlobalOptions GlobalOptions { get; } = globalOptions; } + + /// + /// Gets the hint name for a generated file: its file name, with a short hash of its namespace before the extension. + /// + /// + /// A hint name must be unique within a generator run. File names are made unique within one call to + /// GenerateCode(), but a generator that calls it more than once can produce the same file name twice, for + /// types of the same name in different namespaces (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/651). + /// The hash keeps the hint names apart without making them longer by the whole namespace. + /// + /// The generated file name. + /// The namespace of the file's type, or of the generation for a file with no type. + /// The hint name. + private static string GetHintName(string fileName, string? ns) + { + if (string.IsNullOrEmpty(ns)) + { + return fileName; + } + + // FNV-1a over the namespace, so the hint name is the same in every run and on every platform. + uint hash = 2166136261; + foreach (char c in ns!) + { + hash = (hash ^ c) * 16777619; + } + + // Before ".g.cs" (or the last extension), so that "Foo.g.cs" becomes "Foo.1a2b3c4d.g.cs". + string suffix = "." + hash.ToString("x8", System.Globalization.CultureInfo.InvariantCulture); + int extension = fileName.EndsWith(".g.cs", StringComparison.OrdinalIgnoreCase) + ? fileName.Length - ".g.cs".Length + : fileName.LastIndexOf('.'); + return extension <= 0 + ? fileName + suffix + : fileName.Substring(0, extension) + suffix + fileName.Substring(extension); + } } \ No newline at end of file diff --git a/src-v4/Corvus.Json.SourceGeneratorTools/SourceGeneratorHelpers.cs b/src-v4/Corvus.Json.SourceGeneratorTools/SourceGeneratorHelpers.cs index 3301ff42977..e5c61a7e949 100644 --- a/src-v4/Corvus.Json.SourceGeneratorTools/SourceGeneratorHelpers.cs +++ b/src-v4/Corvus.Json.SourceGeneratorTools/SourceGeneratorHelpers.cs @@ -156,7 +156,7 @@ public static List GenerateCode(SourceProductionContext context { if (!context.CancellationToken.IsCancellationRequested) { - context.AddSource(codeFile.FileName, SourceText.From(codeFile.FileContent, Encoding.UTF8)); + context.AddSource(GetHintName(codeFile.FileName, codeFile.TypeDeclaration?.DotnetNamespace() ?? defaultNamespace), SourceText.From(codeFile.FileContent, Encoding.UTF8)); } } @@ -415,4 +415,40 @@ public readonly struct GlobalOptions(IVocabulary fallbackVocabulary, bool option /// public GeneratedTypeAccessibility DefaultAccessibility { get; } = defaultAccessibility; } + + /// + /// Gets the hint name for a generated file: its file name, with a short hash of its namespace before the extension. + /// + /// + /// A hint name must be unique within a generator run. File names are made unique within one call to + /// GenerateCode(), but a generator that calls it more than once can produce the same file name twice, for + /// types of the same name in different namespaces (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/651). + /// The hash keeps the hint names apart without making them longer by the whole namespace. + /// + /// The generated file name. + /// The namespace of the file's type, or of the generation for a file with no type. + /// The hint name. + private static string GetHintName(string fileName, string? ns) + { + if (string.IsNullOrEmpty(ns)) + { + return fileName; + } + + // FNV-1a over the namespace, so the hint name is the same in every run and on every platform. + uint hash = 2166136261; + foreach (char c in ns!) + { + hash = (hash ^ c) * 16777619; + } + + // Before ".g.cs" (or the last extension), so that "Foo.g.cs" becomes "Foo.1a2b3c4d.g.cs". + string suffix = "." + hash.ToString("x8", System.Globalization.CultureInfo.InvariantCulture); + int extension = fileName.EndsWith(".g.cs", StringComparison.OrdinalIgnoreCase) + ? fileName.Length - ".g.cs".Length + : fileName.LastIndexOf('.'); + return extension <= 0 + ? fileName + suffix + : fileName.Substring(0, extension) + suffix + fileName.Substring(extension); + } } \ No newline at end of file diff --git a/src/Corvus.Json.Cli.Core/GenerateCommand.cs b/src/Corvus.Json.Cli.Core/GenerateCommand.cs index 61efa9d3820..115bdf373ca 100644 --- a/src/Corvus.Json.Cli.Core/GenerateCommand.cs +++ b/src/Corvus.Json.Cli.Core/GenerateCommand.cs @@ -97,7 +97,7 @@ public sealed class Settings : CommandSettings public OptionalAsNullable OptionalAsNullable { get; init; } [CommandOption("--nativeEnums")] - [Description("Controls emission of native C# enums on generated types (V5 engine only). StringEnums emits a nested enum for pure string-enum schemas; FlagsObjects emits a nested [Flags] enum for objects whose declared properties are all boolean; All (the default) emits both; None emits neither.")] + [Description("Controls emission of native C# enums on generated types (V5 engine only). StringEnums emits a nested enum for pure string-enum schemas; FlagsObjects emits a nested [[Flags]] enum for objects whose declared properties are all boolean; All (the default) emits both; None emits neither.")] [DefaultValue(NativeEnums.All)] public NativeEnums NativeEnums { get; init; } @@ -120,6 +120,10 @@ public sealed class Settings : CommandSettings [DefaultValue(GeneratedRegexUnicodeVersion.Default)] public GeneratedRegexUnicodeVersion RegexUnicodeVersion { get; init; } + [CommandOption("--regexMatchTimeout ")] + [Description("The limit, in milliseconds, on one match of a regular expression in generated code that is not proved to match in time proportional to the text, or -1 for none. A match that runs for longer throws RegexMatchTimeoutException. Default is 1000 (1 second).")] + public int? RegexMatchTimeout { get; init; } + [CommandOption("--useImplicitOperatorString")] [Description("If true, conversion operators to string are implicit, rather than explicit.")] [DefaultValue(false)] @@ -192,6 +196,7 @@ protected override Task ExecuteAsync(CommandContext context, Settings setti regexEngine: settings.RegexEngine.ToString(), regexEdition: settings.RegexEdition is GeneratedRegexEdition regexEdition ? (GeneratorConfig.RegexEdition)regexEdition.ToString() : default(GeneratorConfig.RegexEdition?), regexUnicodeVersion: settings.RegexUnicodeVersion.ToString(), + regexMatchTimeout: settings.RegexMatchTimeout is int regexMatchTimeout ? new GeneratorConfig.RegexMatchTimeoutEntity(regexMatchTimeout) : default(GeneratorConfig.RegexMatchTimeoutEntity?), outputMapFile: settings.OutputMapFile.AsNullableJsonString(), outputPath: settings.OutputPath.AsNullableJsonString(), useSchema: settings.UseSchema != SchemaVariant.NotSpecified ? (GeneratorConfig.UseSchema)settings.UseSchema.ToString() : default(GeneratorConfig.UseSchema?), diff --git a/src/Corvus.Json.Cli.Core/GenerationDriverV4.cs b/src/Corvus.Json.Cli.Core/GenerationDriverV4.cs index 5b3719132b1..846b42a8231 100644 --- a/src/Corvus.Json.Cli.Core/GenerationDriverV4.cs +++ b/src/Corvus.Json.Cli.Core/GenerationDriverV4.cs @@ -264,7 +264,8 @@ private static CSharpLanguageProvider.Options MapGeneratorConfigToOptions(in Gen formatModeOverrides: GetFormatModeOverrides(generatorConfig), regexEngine: regexEngine, regexEdition: regexEdition, - regexUnicodeVersion: regexUnicodeVersion); + regexUnicodeVersion: regexUnicodeVersion, + regexMatchTimeoutMilliseconds: (int)(generatorConfig.RegexMatchTimeout ?? GeneratorConfig.RegexMatchTimeoutEntity.DefaultInstance)); } private static IReadOnlyDictionary? GetFormatModeOverrides(in GeneratorConfig generatorConfig) diff --git a/src/Corvus.Json.Cli.Core/GenerationDriverV5.cs b/src/Corvus.Json.Cli.Core/GenerationDriverV5.cs index c8809a5cb7b..2100efa98af 100644 --- a/src/Corvus.Json.Cli.Core/GenerationDriverV5.cs +++ b/src/Corvus.Json.Cli.Core/GenerationDriverV5.cs @@ -304,7 +304,8 @@ private static CodeGeneration.CSharpLanguageProvider.Options MapGeneratorConfigT emitUnions: generatorConfig.Unions ?? true, regexEngine: regexEngine, regexEdition: regexEdition, - regexUnicodeVersion: regexUnicodeVersion); + regexUnicodeVersion: regexUnicodeVersion, + regexMatchTimeoutMilliseconds: (int)(generatorConfig.RegexMatchTimeout ?? GeneratorConfig.RegexMatchTimeoutEntity.DefaultInstance)); } private static IReadOnlyDictionary? GetFormatModeOverrides(in GeneratorConfig generatorConfig) diff --git a/src/Corvus.Json.Cli.Core/generator-config.json b/src/Corvus.Json.Cli.Core/generator-config.json index 0355bc2a40a..006e3c0ab18 100644 --- a/src/Corvus.Json.Cli.Core/generator-config.json +++ b/src/Corvus.Json.Cli.Core/generator-config.json @@ -102,6 +102,13 @@ "regexUnicodeVersion": { "$ref": "#/$defs/regexUnicodeVersion", "description": "The version of Unicode every pattern is read with (Ecma262 regular expressions only). Default is the version V8 uses (17)." + }, + "regexMatchTimeout": { + "type": "integer", + "minimum": -1, + "not": { "const": 0 }, + "default": 1000, + "description": "The limit, in milliseconds, on one match of a regular expression in generated code that is not proved to match in time proportional to the text, or -1 for none. A match that runs for longer throws RegexMatchTimeoutException. Default is 1000 (1 second)." } }, "$defs": { diff --git a/src/Corvus.Text.Json.CodeGeneration/CSharpLanguageProvider.cs b/src/Corvus.Text.Json.CodeGeneration/CSharpLanguageProvider.cs index a51dc8cf987..3f93dfb2d9a 100644 --- a/src/Corvus.Text.Json.CodeGeneration/CSharpLanguageProvider.cs +++ b/src/Corvus.Text.Json.CodeGeneration/CSharpLanguageProvider.cs @@ -103,7 +103,10 @@ public void SetEvaluatorRootTypes(params TypeDeclaration[] rootTypes) internal const string ProgramClassName = "CorvusJsonSchemaProgram"; /// Gets the regular expressions of this generation, each written once (see ). - internal SharedRegularExpressions SharedRegularExpressions => this.sharedRegularExpressions ??= new(options.DefaultNamespace); + internal SharedRegularExpressions SharedRegularExpressions => this.sharedRegularExpressions ??= new(options.DefaultNamespace, options.RegexMatchTimeoutMilliseconds); + + /// Gets the limit, in milliseconds, on one match of a regular expression of the generated code, or -1 for none. + internal int RegexMatchTimeoutMilliseconds => options.RegexMatchTimeoutMilliseconds; /// Gets the fully qualified reference to the program class for use in generated code. internal string ProgramClassReference => options.DefaultNamespace.Length == 0 ? "global::" + ProgramClassName : "global::" + options.DefaultNamespace + "." + ProgramClassName; @@ -511,7 +514,8 @@ public void GenerateCodeFor(IEnumerable typeDeclarations, IGene image, options.RegexEngine == GeneratedRegexEngine.Ecma262 ? options.RegexEdition : null, options.RegexEngine == GeneratedRegexEngine.Ecma262 ? options.RegexUnicodeVersion : GeneratedRegexUnicodeVersion.Default, - regex => this.SharedRegularExpressions.Reference(regex.Pattern, regex.Unicode, regex.Edition, regex.UnicodeVersion))); + regex => this.SharedRegularExpressions.Reference(regex.Pattern, regex.Unicode, regex.Edition, regex.UnicodeVersion), + options.RegexMatchTimeoutMilliseconds)); } // Last, as the types and the program have now asked for every regular expression they refer to. @@ -1141,6 +1145,7 @@ private sealed class CollectingSink(List files) : IGeneratedC /// The engine the regular expressions of generated code are written for (see ). Defaults to . /// The edition of the grammar every pattern is read with, or (the default) for the dialect's: ECMAScript 2020 for draft 2019-09 and draft 2020-12, today's for the others. For only. /// The version of Unicode every pattern is read with. For only. + /// The limit, in milliseconds, on one match of a regular expression of generated code that is not proved to match in time proportional to the text, or -1 for none. Defaults to 1,000 (1 second). public class Options( string defaultNamespace, NamedType[]? namedTypes = null, @@ -1165,10 +1170,16 @@ public class Options( bool storeFilesAsStrings = false, GeneratedRegexEngine regexEngine = GeneratedRegexEngine.Ecma262, GeneratedRegexEdition? regexEdition = null, - GeneratedRegexUnicodeVersion regexUnicodeVersion = GeneratedRegexUnicodeVersion.Default) + GeneratedRegexUnicodeVersion regexUnicodeVersion = GeneratedRegexUnicodeVersion.Default, + int regexMatchTimeoutMilliseconds = CodeGenerationExtensions.DefaultRegexMatchTimeoutMilliseconds) { internal bool EmitUnions { get; } = emitUnions; + /// Gets the limit, in milliseconds, on one match of a regular expression of generated code, or -1 for none. + internal int RegexMatchTimeoutMilliseconds { get; } = regexMatchTimeoutMilliseconds == global::System.Threading.Timeout.Infinite || regexMatchTimeoutMilliseconds > 0 + ? regexMatchTimeoutMilliseconds + : throw new ArgumentOutOfRangeException(nameof(regexMatchTimeoutMilliseconds), regexMatchTimeoutMilliseconds, "The match timeout is a positive number of milliseconds, or -1 for none."); + /// Gets the engine the regular expressions of generated code are written for. internal GeneratedRegexEngine RegexEngine { get; } = regexEngine; diff --git a/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/CorePartial.cs b/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/CorePartial.cs index 95353118e24..f27c98612cd 100644 --- a/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/CorePartial.cs +++ b/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/CorePartial.cs @@ -54,6 +54,7 @@ public CodeGenerator EmitFile(CodeGenerator generator, TypeDeclaration typeDecla typeDeclaration.DotnetTypeName(), interfaces: [ typeDeclaration.GetIJsonElementInterface(forMutable: false), + typeDeclaration.GetReadOnlyCollectionInterface(), "IFormattable", new("ISpanFormattable", FrameworkType.Net80OrGreater), new("IUtf8SpanFormattable", FrameworkType.Net80OrGreater), @@ -84,6 +85,7 @@ public CodeGenerator EmitFile(CodeGenerator generator, TypeDeclaration typeDecla .AppendGetArrayLength(typeDeclaration) .AppendGetPropertyCount(typeDeclaration) .AppendEnumerateArray(typeDeclaration) + .AppendReadOnlyCollectionImplementation(typeDeclaration) .AppendEnumerateObject(typeDeclaration) .AppendValueKindProperty() .AppendTokenTypeProperty() diff --git a/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/MutableCorePartial.cs b/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/MutableCorePartial.cs index 1c8efa807a1..5ba6a0262bc 100644 --- a/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/MutableCorePartial.cs +++ b/src/Corvus.Text.Json.CodeGeneration/CodeFileBuilders/MutableCorePartial.cs @@ -100,6 +100,7 @@ public CodeGenerator EmitFile(CodeGenerator generator, TypeDeclaration typeDecla .AppendEqualsOverloads(typeDeclaration) .AppendValueEqualsOverloads(typeDeclaration) .AppendObjectPropertySetters(typeDeclaration) + .AppendApplyDefaultsMethod(typeDeclaration) .AppendApplyObjectCompositionTypes(typeDeclaration) .AppendWriteToMethod() .AppendGetHashCodeAndToStringMethods(typeDeclaration, forMutable: true) diff --git a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Array.cs b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Array.cs index a3c6cbb852a..9996843d949 100644 --- a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Array.cs +++ b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Array.cs @@ -750,29 +750,9 @@ public static CodeGenerator AppendEnumerateArray(this CodeGenerator generator, T return generator; } - string fqdtn; - - if (typeDeclaration.ArrayItemsType() is ArrayItemsTypeDeclaration itemsType) + if (!TryGetArrayItemsTypeName(typeDeclaration, out string fqdtn)) { - if (itemsType.ReducedType == WellKnownTypeDeclarations.JsonNotAny) - { - return generator; - } - - fqdtn = itemsType.ReducedType.FullyQualifiedDotnetTypeName(); - } - else if (typeDeclaration.ExplicitUnevaluatedItemsType() is ArrayItemsTypeDeclaration unevaluatedItemsType) - { - if (unevaluatedItemsType.ReducedType == WellKnownTypeDeclarations.JsonNotAny) - { - return generator; - } - - fqdtn = unevaluatedItemsType.ReducedType.FullyQualifiedDotnetTypeName(); - } - else - { - fqdtn = WellKnownTypeDeclarations.JsonAny.DotnetTypeName(); + return generator; } if (forMutable) @@ -793,6 +773,86 @@ public static CodeGenerator AppendEnumerateArray(this CodeGenerator generator, T .AppendLineIndent("}"); } + /// + /// Gets the type of the items EnumerateArray() gives, or when the items cannot be + /// anything (a false items schema). + /// + private static bool TryGetArrayItemsTypeName(TypeDeclaration typeDeclaration, out string fqdtn) + { + if (typeDeclaration.ArrayItemsType() is ArrayItemsTypeDeclaration itemsType) + { + fqdtn = itemsType.ReducedType.FullyQualifiedDotnetTypeName(); + return itemsType.ReducedType != WellKnownTypeDeclarations.JsonNotAny; + } + + if (typeDeclaration.ExplicitUnevaluatedItemsType() is ArrayItemsTypeDeclaration unevaluatedItemsType) + { + fqdtn = unevaluatedItemsType.ReducedType.FullyQualifiedDotnetTypeName(); + return unevaluatedItemsType.ReducedType != WellKnownTypeDeclarations.JsonNotAny; + } + + fqdtn = WellKnownTypeDeclarations.JsonAny.DotnetTypeName(); + return true; + } + + /// + /// Gets the type of the items of a pure array type, whose only core type is array and which is not a tuple, + /// or for any other type. Such a type is a read-only collection of its items. + /// + private static string? PureArrayItemsTypeName(TypeDeclaration typeDeclaration) + { + return typeDeclaration.ImpliedCoreTypes() == CoreTypes.Array && + typeDeclaration.TupleType() is null && + TryGetArrayItemsTypeName(typeDeclaration, out string fqdtn) + ? fqdtn + : null; + } + + /// + /// Gets the IReadOnlyCollection<T> interface of a pure array type, or nothing for any other type. + /// + /// The type declaration. + /// The interface to declare, or . + public static ConditionalCodeSpecification GetReadOnlyCollectionInterface(this TypeDeclaration typeDeclaration) + { + return PureArrayItemsTypeName(typeDeclaration) is string itemsType + ? "global::System.Collections.Generic.IReadOnlyCollection<" + itemsType + ">" + : ConditionalCodeSpecification.DoNotEmit; + } + + /// + /// Appends the members of IReadOnlyCollection<T> for a pure array type, and a GetEnumerator() + /// that returns the array enumerator, so that foreach over the value does not allocate. + /// + /// The code generator. + /// The type declaration for which to emit the members. + /// A reference to the generator having completed the operation. + public static CodeGenerator AppendReadOnlyCollectionImplementation(this CodeGenerator generator, TypeDeclaration typeDeclaration) + { + if (generator.IsCancellationRequested || PureArrayItemsTypeName(typeDeclaration) is not string itemsType) + { + return generator; + } + + return generator + .ReserveNameIfNotReserved("GetEnumerator") + .AppendSeparatorLine() + .AppendLineIndent("/// ") + .AppendLineIndent("/// Gets an enumerator over the items of the array, for foreach. It does not allocate.") + .AppendLineIndent("/// ") + .AppendLineIndent("/// The enumerator.") + .AppendLineIndent("public ArrayEnumerator<", itemsType, "> GetEnumerator() => EnumerateArray();") + .AppendSeparatorLine() + .AppendLineIndent("/// ") + .AppendLineIndent("global::System.Collections.Generic.IEnumerator<", itemsType, "> global::System.Collections.Generic.IEnumerable<", itemsType, ">.GetEnumerator() => EnumerateArray();") + .AppendSeparatorLine() + .AppendLineIndent("/// ") + .AppendLineIndent("global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => EnumerateArray();") + .AppendSeparatorLine() + .AppendLineIndent("/// ") + .AppendLineIndent("int global::System.Collections.Generic.IReadOnlyCollection<", itemsType, ">.Count => GetArrayLength();"); + } + /// /// Append GetArrayLength() method. /// diff --git a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.CloneAndFreeze.cs b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.CloneAndFreeze.cs index 6834655b64c..dfbaf7719bc 100644 --- a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.CloneAndFreeze.cs +++ b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.CloneAndFreeze.cs @@ -34,6 +34,14 @@ public static CodeGenerator AppendCloneMethod(this CodeGenerator generator, Type .AppendLineIndent("{") .PushIndent() .AppendLineIndent("CheckValidInstance();") + .AppendLineIndent("if (!_parent.IsDisposable)") + .AppendLineIndent("{") + .PushIndent() + .AppendLineIndent("// Already a clone, or backed by a document that is never disposed.") + .AppendLineIndent("return this;") + .PopIndent() + .AppendLineIndent("}") + .AppendSeparatorLine() .AppendLineIndent("return _parent.CloneElement<", typeName, ">(_idx);") .PopIndent() .AppendLineIndent("}"); diff --git a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.JsonSchema.cs b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.JsonSchema.cs index 628d4592ef7..cdd0225104d 100644 --- a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.JsonSchema.cs +++ b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.JsonSchema.cs @@ -47,18 +47,19 @@ internal static partial class CodeGenerationExtensions private const string MutableClassNameKey = "CSharp_JsonSchema_MutableClassNameKey"; /// - /// The match timeout, in milliseconds, of every regular expression in generated code that is not proved to - /// match in time proportional to the text: 1 second. + /// The default match timeout, in milliseconds, of every regular expression in generated code that is not proved + /// to match in time proportional to the text: 1 second. CSharpLanguageProvider.Options sets another, or + /// none (-1). /// /// /// There are patterns on which a match in .NET's regular expression engine never finishes. With a timeout the /// match throws to the caller of the - /// generated code. This is the one place the generator holds the value. The runtime evaluator has the same + /// generated code. This is the one place the generator holds the default. The runtime evaluator has the same /// default for the expressions it constructs, in JsonSchemaEvaluatorOptions.DefaultRegexMatchTimeout. /// A pattern that EcmaRegexTranslator.IsLinear proves linear has no timeout, in generated code and in /// the evaluator. /// - internal const int RegexMatchTimeoutMilliseconds = 1_000; + internal const int DefaultRegexMatchTimeoutMilliseconds = 1_000; // Both end in \z and not in $, which in .NET also holds before a final line feed. A pattern that ends in a // line feed (^abc\n) is neither of these. @@ -406,16 +407,18 @@ private static CodeGenerator AppendRegexValidationFactoryMethod(this CodeGenerat string memberName = generator.GetMethodNameInScope(keyword.Keyword, prefix: "Create", suffix: index?.ToString(CultureInfo.InvariantCulture)); - // Every form carries the match timeout (see RegexMatchTimeoutMilliseconds), but for a pattern proved to - // match in time proportional to the text, which has none (see EcmaRegexTranslator.IsLinear). The timeout - // makes .NET's engines check the clock as they match, which costs that pattern up to half its time again. - bool linear = EcmaRegexTranslator.IsLinear(value); - string timeout = linear + // Every form carries the generation's match timeout (1 second unless the options say otherwise), but for a + // pattern proved to match in time proportional to the text, which has none (see EcmaRegexTranslator.IsLinear). + // The timeout makes .NET's engines check the clock as they match, which costs that pattern up to half its time + // again. + int matchTimeout = ((CSharpLanguageProvider)generator.LanguageProvider).RegexMatchTimeoutMilliseconds; + bool unlimited = matchTimeout == global::System.Threading.Timeout.Infinite || EcmaRegexTranslator.IsLinear(value); + string timeout = unlimited ? "global::System.Text.RegularExpressions.Regex.InfiniteMatchTimeout" - : "global::System.TimeSpan.FromMilliseconds(" + RegexMatchTimeoutMilliseconds.ToString(CultureInfo.InvariantCulture) + ")"; - string generatedTimeout = linear + : "global::System.TimeSpan.FromMilliseconds(" + matchTimeout.ToString(CultureInfo.InvariantCulture) + ")"; + string generatedTimeout = unlimited ? "global::System.Threading.Timeout.Infinite" - : RegexMatchTimeoutMilliseconds.ToString(CultureInfo.InvariantCulture); + : matchTimeout.ToString(CultureInfo.InvariantCulture); #if !BUILDING_SOURCE_GENERATOR if (translatedValue.StartsWith(EcmaRegexTranslator.InterpretedMarker, StringComparison.Ordinal)) diff --git a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Object.cs b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Object.cs index 92c0760d325..2362f09710b 100644 --- a/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Object.cs +++ b/src/Corvus.Text.Json.CodeGeneration/CodeGeneratorExtensions.Object.cs @@ -1026,6 +1026,95 @@ public PatternPropertyMethodInfo( public string VisitPatternName { get; } } + /// + /// Appends the ApplyDefaults() method of a mutable object type: it sets each absent property that has a + /// default in the schema to that default, and then applies the defaults of each property whose type has properties. + /// + /// The code generator. + /// The type declaration for which to emit the method. + /// A reference to the generator having completed the operation. + public static CodeGenerator AppendApplyDefaultsMethod(this CodeGenerator generator, TypeDeclaration typeDeclaration) + { + if (generator.IsCancellationRequested || typeDeclaration.PropertyDeclarations.Count == 0) + { + return generator; + } + + generator + .AppendSeparatorLine() + .AppendLineIndent("/// ") + .AppendLineIndent("/// Adds to the document each property that is absent and has a default in the schema, with that default") + .AppendLineIndent("/// as its value, and then does the same inside each property whose own type has properties.") + .AppendLineIndent("/// ") + .AppendLineIndent("/// ") + .AppendLineIndent("/// ") + .AppendLineIndent("/// This changes the data. Reading an absent property already gives its default without it; this method writes") + .AppendLineIndent("/// the defaults into the document as additional properties, so that they are there when the document is sent") + .AppendLineIndent("/// to a system that does not apply the schema's defaults itself.") + .AppendLineIndent("/// ") + .AppendLineIndent("/// ") + .AppendLineIndent("/// A property that is present keeps its value. Does nothing when the value is not an object. The items of") + .AppendLineIndent("/// arrays are not visited. The result is not validated: a default that does not satisfy its schema is written") + .AppendLineIndent("/// as it is.") + .AppendLineIndent("/// ") + .AppendLineIndent("/// ") + .AppendLineIndent("public void ApplyDefaults()") + .AppendLineIndent("{") + .PushIndent() + .AppendLineIndent("CheckValidInstance();") + .AppendLineIndent("if (ValueKind != JsonValueKind.Object)") + .AppendLineIndent("{") + .PushIndent() + .AppendLineIndent("return;") + .PopIndent() + .AppendLineIndent("}"); + + // First the defaults of the absent properties, so that the defaults written are visited below too. + foreach (PropertyDeclaration property in typeDeclaration.PropertyDeclarations) + { + if (property.ReducedPropertyType.IsBuiltInJsonNotAnyType() || + property.ReducedPropertyType.DefaultValue().ValueKind == JsonValueKind.Undefined) + { + continue; + } + + generator + .AppendSeparatorLine() + .AppendLineIndent("if (!_parent.TryGetNamedPropertyValue(_idx, ", generator.JsonPropertyNamesClassName(), ".", property.DotnetPropertyName(), "Utf8, out IJsonDocument? _, out int _))") + .AppendLineIndent("{") + .PushIndent() + .AppendLineIndent("Set", property.DotnetPropertyName(), "(", property.ReducedPropertyType.FullyQualifiedDotnetTypeName(), ".DefaultInstance);") + .PopIndent() + .AppendLineIndent("}"); + } + + // Then the properties whose types have properties of their own. Each is looked up after the writes above, and + // the version is taken again after each, as a write inside a property changes the document. + foreach (PropertyDeclaration property in typeDeclaration.PropertyDeclarations) + { + if (property.ReducedPropertyType.IsBuiltInJsonNotAnyType() || + property.ReducedPropertyType.PropertyDeclarations.Count == 0) + { + continue; + } + + string propertyMutableType = property.ReducedPropertyType.FullyQualifiedDotnetTypeName() + ".Mutable"; + generator + .AppendSeparatorLine() + .AppendLineIndent("if (_parent.TryGetNamedPropertyValue(_idx, ", generator.JsonPropertyNamesClassName(), ".", property.DotnetPropertyName(), "Utf8, out ", propertyMutableType, " ", "__corvus", property.DotnetPropertyName(), "))") + .AppendLineIndent("{") + .PushIndent() + .AppendLineIndent("__corvus", property.DotnetPropertyName(), ".ApplyDefaults();") + .AppendLineIndent("_documentVersion = _parent.Version;") + .PopIndent() + .AppendLineIndent("}"); + } + + return generator + .PopIndent() + .AppendLineIndent("}"); + } + public static CodeGenerator AppendObjectPropertySetters(this CodeGenerator generator, TypeDeclaration typeDeclaration) { if (generator.IsCancellationRequested) diff --git a/src/Corvus.Text.Json.CodeGeneration/Formatting.cs b/src/Corvus.Text.Json.CodeGeneration/Formatting.cs index 4c62d5a9e14..d22673a851b 100644 --- a/src/Corvus.Text.Json.CodeGeneration/Formatting.cs +++ b/src/Corvus.Text.Json.CodeGeneration/Formatting.cs @@ -73,6 +73,7 @@ public static class Formatting "_parent", "_idx", "_documentVersion", + "ApplyDefaults", "ArrayBuilder", "AsJsonElement", "Assert", diff --git a/src/Corvus.Text.Json.CodeGeneration/RuntimeProgramGenerator.cs b/src/Corvus.Text.Json.CodeGeneration/RuntimeProgramGenerator.cs index 240e8f63579..00e7d805485 100644 --- a/src/Corvus.Text.Json.CodeGeneration/RuntimeProgramGenerator.cs +++ b/src/Corvus.Text.Json.CodeGeneration/RuntimeProgramGenerator.cs @@ -387,6 +387,7 @@ private static string CommonDirectory(IEnumerable paths) /// The version of Unicode every pattern is read with. /// Gives the reference to the shared compiled matcher of a regular /// expression of the table, or to write each in the program. + /// The limit, in milliseconds, on one match, or -1 for none. /// The generated file. public static GeneratedCodeFile Generate( string ns, @@ -402,7 +403,8 @@ public static GeneratedCodeFile Generate( SchemaProgramImage? image = null, GeneratedRegexEdition? regexEdition = null, GeneratedRegexUnicodeVersion regexUnicodeVersion = GeneratedRegexUnicodeVersion.Default, - Func? sharedRegularExpression = null) + Func? sharedRegularExpression = null, + int regexMatchTimeoutMilliseconds = CodeGenerationExtensions.DefaultRegexMatchTimeoutMilliseconds) { var sb = new StringBuilder(); void Line(string text = "") @@ -504,7 +506,9 @@ void Line(string text = "") // The expressions the evaluator constructs itself (every one of them when there is no [GeneratedRegex] table, // or no regex generator to implement it) have the timeout the table's expressions have. - Line($" RegexMatchTimeout = global::System.TimeSpan.FromMilliseconds({CodeGenerationExtensions.RegexMatchTimeoutMilliseconds}),"); + Line(regexMatchTimeoutMilliseconds == global::System.Threading.Timeout.Infinite + ? " RegexMatchTimeout = global::System.Text.RegularExpressions.Regex.InfiniteMatchTimeout," + : $" RegexMatchTimeout = global::System.TimeSpan.FromMilliseconds({regexMatchTimeoutMilliseconds}),"); if (formatModes.Count > 0) { Line(" FormatModes = new global::System.Collections.Generic.Dictionary(global::System.StringComparer.Ordinal)"); @@ -537,7 +541,7 @@ void Line(string text = "") Line(); if (image is not null) { - EmitImage(Line, image, sharedRegularExpression); + EmitImage(Line, image, sharedRegularExpression, regexMatchTimeoutMilliseconds); Line("}"); return new GeneratedCodeFile(className + fileExtension, sb.ToString()); } @@ -577,13 +581,14 @@ void Line(string text = "") /// Emits the image (base64 in UTF-8 literals, decoded on first use) and the regular-expression table: one /// [GeneratedRegex] method per pattern, in the image's pattern-table order, on runtimes that have the /// generator; elsewhere the provider returns and the evaluator constructs the expression. - /// Each has the match timeout of : the - /// attribute carries it, and the options the program is loaded with carry it for the evaluator's own. A pattern - /// proved linear () has none, in both. + /// Each has the generation's match timeout (1 second by default, see + /// ): the attribute carries it, and the + /// options the program is loaded with carry it for the evaluator's own. A pattern proved linear + /// () has none, in both. /// A program from a Roslyn source generator carries no patterns (generators do not chain, so the regex generator /// would never implement the methods) and the evaluator constructs every expression on first use. /// - private static void EmitImage(Action line, SchemaProgramImage image, Func? sharedRegularExpression) + private static void EmitImage(Action line, SchemaProgramImage image, Func? sharedRegularExpression, int regexMatchTimeoutMilliseconds) { line(" private static byte[] LoadImage()"); line(" {"); @@ -633,9 +638,9 @@ private static void EmitImage(Action line, SchemaProgramImage image, Fun { // A pattern proved to match in time proportional to the text has no timeout, as in the evaluator. bool linear = image.EcmaPatterns.Count == image.DotNetPatterns.Count && EcmaRegexTranslator.IsLinear(image.EcmaPatterns[i]); - string timeout = linear + string timeout = linear || regexMatchTimeoutMilliseconds == global::System.Threading.Timeout.Infinite ? "global::System.Threading.Timeout.Infinite" - : CodeGenerationExtensions.RegexMatchTimeoutMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture); + : regexMatchTimeoutMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture); line($" [GeneratedRegex({Literal(image.DotNetPatterns[i])}, RegexOptions.CultureInvariant, matchTimeoutMilliseconds: {timeout})]"); line($" private static partial Regex Regex{i}();"); } @@ -644,7 +649,7 @@ private static void EmitImage(Action line, SchemaProgramImage image, Fun line("#endif"); } - EmitEcmaRegularExpressions(line, image.EcmaRegularExpressions, sharedRegularExpression); + EmitEcmaRegularExpressions(line, image.EcmaRegularExpressions, sharedRegularExpression, regexMatchTimeoutMilliseconds); line(string.Empty); string base64 = Convert.ToBase64String(image.Image); line($" // Program image: {image.Image.Length} bytes."); @@ -852,7 +857,7 @@ public static string DialectFor(IVocabulary vocabulary) /// evaluator each by its index. The evaluator uses one only when it is the pattern compiled as it would compile /// it. A pattern read with two editions (by dialects that read patterns differently) has a matcher for the first. /// - private static void EmitEcmaRegularExpressions(Action line, IReadOnlyList regularExpressions, Func? sharedRegularExpression) + private static void EmitEcmaRegularExpressions(Action line, IReadOnlyList regularExpressions, Func? sharedRegularExpression, int regexMatchTimeoutMilliseconds) { if (regularExpressions.Count == 0) { @@ -896,7 +901,7 @@ private static void EmitEcmaRegularExpressions(Action line, IReadOnlyLis if (!Corvus.Ecma262.RegularExpressions.CodeGeneration.RegexEmitter.TryEmit( regex.Pattern, regex.Unicode ? Corvus.Ecma262.RegularExpressions.CodeGeneration.RegexFlags.Unicode : Corvus.Ecma262.RegularExpressions.CodeGeneration.RegexFlags.None, - CodeGenerationExtensions.RegexMatchTimeoutMilliseconds, + regexMatchTimeoutMilliseconds, (Corvus.Ecma262.RegularExpressions.CodeGeneration.RegexEdition)(int)regex.Edition, (Corvus.Ecma262.RegularExpressions.CodeGeneration.RegexUnicodeVersion)(int)regex.UnicodeVersion, holder, diff --git a/src/Corvus.Text.Json.CodeGeneration/SharedRegularExpressions.cs b/src/Corvus.Text.Json.CodeGeneration/SharedRegularExpressions.cs index 078a956b768..0d973ebcb02 100644 --- a/src/Corvus.Text.Json.CodeGeneration/SharedRegularExpressions.cs +++ b/src/Corvus.Text.Json.CodeGeneration/SharedRegularExpressions.cs @@ -29,11 +29,14 @@ internal sealed class SharedRegularExpressions private readonly List<(string Name, string Pattern, bool Unicode, GeneratedRegexEdition Edition, GeneratedRegexUnicodeVersion UnicodeVersion)> entries = []; private readonly object sync = new(); private readonly string classReference; + private readonly int matchTimeoutMilliseconds; /// Initializes a new instance of the class. /// The namespace the class is written in (the program's). - public SharedRegularExpressions(string defaultNamespace) + /// The limit, in milliseconds, on one match, or -1 for none. + public SharedRegularExpressions(string defaultNamespace, int matchTimeoutMilliseconds = CodeGenerationExtensions.DefaultRegexMatchTimeoutMilliseconds) { + this.matchTimeoutMilliseconds = matchTimeoutMilliseconds; this.Namespace = defaultNamespace; this.classReference = defaultNamespace.Length == 0 ? "global::" + ClassName : "global::" + defaultNamespace + "." + ClassName; } @@ -111,7 +114,7 @@ public string Reference(string pattern, bool unicode, GeneratedRegexEdition edit if (!EcmaRegexEmitter.TryEmit( pattern, unicode ? EcmaRegexFlags.Unicode : EcmaRegexFlags.None, - CodeGenerationExtensions.RegexMatchTimeoutMilliseconds, + this.matchTimeoutMilliseconds, (EcmaRegexEdition)(int)edition, (EcmaRegexUnicodeVersion)(int)unicodeVersion, holder, diff --git a/src/Corvus.Text.Json.Patch/JsonMergePatchExtensions.cs b/src/Corvus.Text.Json.Patch/JsonMergePatchExtensions.cs index 66d81a7f0b4..c43154f2f79 100644 --- a/src/Corvus.Text.Json.Patch/JsonMergePatchExtensions.cs +++ b/src/Corvus.Text.Json.Patch/JsonMergePatchExtensions.cs @@ -87,7 +87,7 @@ private static void ReplaceRoot(ref JsonElement.Mutable target, in JsonElement.S ComplexValueBuilder cvb = ComplexValueBuilder.Create(mutableDoc, 30); value.AddAsItem(ref cvb); mutableDoc.ReplaceRootAndDispose(ref cvb); - target = ((JsonDocumentBuilder)mutableDoc).RootElement; + target = RootOf(mutableDoc); } private static void ReplaceRootWithEmptyObject(ref JsonElement.Mutable target) @@ -96,7 +96,7 @@ private static void ReplaceRootWithEmptyObject(ref JsonElement.Mutable target) ComplexValueBuilder cvb = ComplexValueBuilder.Create(mutableDoc, 0); JsonElement.ObjectBuilder.BuildValue(static (ref JsonElement.ObjectBuilder _) => { }, ref cvb); mutableDoc.ReplaceRootAndDispose(ref cvb); - target = ((JsonDocumentBuilder)mutableDoc).RootElement; + target = RootOf(mutableDoc); } private static IMutableJsonDocument GetMutableDoc(in T element) @@ -104,4 +104,21 @@ private static IMutableJsonDocument GetMutableDoc(in T element) { return (IMutableJsonDocument)element.ParentDocument; } + + private static JsonElement.Mutable RootOf(IMutableJsonDocument document) + { + // The root of a builder is its first row, whatever the type of its root element (a generated type's builder + // is not a JsonDocumentBuilder). + return CreateRoot(document); + + static T CreateRoot(IMutableJsonDocument document) + where T : struct, IJsonElement + { +#if NET + return T.CreateInstance(document, 0); +#else + return JsonElementHelpers.CreateInstance(document, 0); +#endif + } + } } \ No newline at end of file diff --git a/src/Corvus.Text.Json.Patch/JsonPatchExtensions.cs b/src/Corvus.Text.Json.Patch/JsonPatchExtensions.cs index 1b55d564a4e..3c9c1966659 100644 --- a/src/Corvus.Text.Json.Patch/JsonPatchExtensions.cs +++ b/src/Corvus.Text.Json.Patch/JsonPatchExtensions.cs @@ -48,6 +48,54 @@ public static bool TryValidateAndApplyPatch(this ref JsonElement.Mutable target, return TryApplyPatch(ref target, in patch); } + /// + /// Validates an RFC 6902 JSON Patch document against its schema, and if valid, + /// tries to apply it to a mutable element of a generated type. + /// + /// The generated mutable type (for example MySchema.Mutable). + /// The mutable element to patch. On return it refers to the patched value. + /// The patch document to validate and apply. + /// if the patch document is valid and all operations + /// were applied successfully; otherwise, . + /// + /// The patch is applied to the element's document as + /// applies it. The result is not validated against the schema of ; call + /// EvaluateSchema() on it for that. + /// + public static bool TryValidateAndApplyPatch(this ref T target, in JsonPatchDocument patch) + where T : struct, IMutableJsonElement + { + if (!patch.EvaluateSchema()) + { + return false; + } + + return TryApplyPatch(ref target, in patch); + } + + /// + /// Tries to apply an RFC 6902 JSON Patch document to a mutable element of a generated type. + /// + /// The generated mutable type (for example MySchema.Mutable). + /// The mutable element to patch. On return it refers to the patched value. + /// The patch document to apply. + /// if all operations were applied successfully; otherwise, . + /// + /// The patch is applied to the element's document as + /// applies it, with the same assumption that the patch document is valid. The result is not validated against + /// the schema of ; call EvaluateSchema() on it for that. + /// + public static bool TryApplyPatch(this ref T target, in JsonPatchDocument patch) + where T : struct, IMutableJsonElement + { + JsonElement.Mutable element = JsonElement.Mutable.From(in target); + bool applied = TryApplyPatch(ref element, in patch); + + // A patch at the root can replace the value, so the element is made again from where the patch left it. + target = Rewrap(in element); + return applied; + } + /// /// Tries to apply an RFC 6902 JSON Patch document to a mutable JSON element. /// @@ -1216,7 +1264,7 @@ private static void ReplaceRoot(ref JsonElement.Mutable target, in JsonElement.S mutableDoc.ReplaceRootAndDispose(ref cvb); // Re-acquire the root element after replacement. - target = ((JsonDocumentBuilder)mutableDoc).RootElement; + target = RootOf(mutableDoc); } private static bool IsAppendToken(ReadOnlySpan segment) @@ -1285,4 +1333,33 @@ private static int GetUtf8Bytes(ReadOnlySpan chars, Span destination } #endif } + + private static T Rewrap(in TSource source) + where T : struct, IJsonElement + where TSource : struct, IJsonElement + { + // The constraint reads the explicitly implemented members without boxing. +#if NET + return T.CreateInstance(source.ParentDocument, source.ParentDocumentIndex); +#else + return JsonElementHelpers.CreateInstance(source.ParentDocument, source.ParentDocumentIndex); +#endif + } + + private static JsonElement.Mutable RootOf(IMutableJsonDocument document) + { + // The root of a builder is its first row, whatever the type of its root element (a generated type's builder + // is not a JsonDocumentBuilder). + return CreateRoot(document); + + static T CreateRoot(IMutableJsonDocument document) + where T : struct, IJsonElement + { +#if NET + return T.CreateInstance(document, 0); +#else + return JsonElementHelpers.CreateInstance(document, 0); +#endif + } + } } \ No newline at end of file diff --git a/src/Corvus.Text.Json.SourceGenerator/Corvus.Text.Json.SourceGenerator.props b/src/Corvus.Text.Json.SourceGenerator/Corvus.Text.Json.SourceGenerator.props index 5f148fa1577..b965dc7bda8 100644 --- a/src/Corvus.Text.Json.SourceGenerator/Corvus.Text.Json.SourceGenerator.props +++ b/src/Corvus.Text.Json.SourceGenerator/Corvus.Text.Json.SourceGenerator.props @@ -15,5 +15,6 @@ + diff --git a/src/Corvus.Text.Json.SourceGenerator/IncrementalSourceGenerator.cs b/src/Corvus.Text.Json.SourceGenerator/IncrementalSourceGenerator.cs index 9b58bf2ceb6..57e527e5504 100644 --- a/src/Corvus.Text.Json.SourceGenerator/IncrementalSourceGenerator.cs +++ b/src/Corvus.Text.Json.SourceGenerator/IncrementalSourceGenerator.cs @@ -206,6 +206,16 @@ private static GlobalOptions GetGlobalOptions(VocabularyRegistry vocabularyRegis }; } + int regexMatchTimeoutMilliseconds = Text.Json.CodeGeneration.CodeGenerationExtensions.DefaultRegexMatchTimeoutMilliseconds; + if (source.GlobalOptions.TryGetValue("build_property.CorvusTextJsonRegexMatchTimeout", out string? regexMatchTimeoutName) && regexMatchTimeoutName.Length > 0) + { + if (!int.TryParse(regexMatchTimeoutName, System.Globalization.NumberStyles.AllowLeadingSign, System.Globalization.CultureInfo.InvariantCulture, out regexMatchTimeoutMilliseconds) || + (regexMatchTimeoutMilliseconds != -1 && regexMatchTimeoutMilliseconds <= 0)) + { + throw new InvalidOperationException($"Invalid build property value for 'CorvusTextJsonRegexMatchTimeout': '{regexMatchTimeoutName}'. Expected a positive number of milliseconds, or -1 for no limit."); + } + } + bool addExplicitUsings = true; if (source.GlobalOptions.TryGetValue("build_property.CorvusTextJsonAddExplicitUsings", out string? addExplicitUsingsName)) @@ -307,7 +317,8 @@ private static GlobalOptions GetGlobalOptions(VocabularyRegistry vocabularyRegis emitUnions, regexEngine, regexEdition, - regexUnicodeVersion); + regexUnicodeVersion, + regexMatchTimeoutMilliseconds); } private static void EmitGeneratorAttribute(IncrementalGeneratorInitializationContext initializationContext) @@ -380,7 +391,8 @@ private class GlobalOptions( bool emitUnions, Text.Json.CodeGeneration.GeneratedRegexEngine regexEngine, Text.Json.CodeGeneration.GeneratedRegexEdition? regexEdition, - Text.Json.CodeGeneration.GeneratedRegexUnicodeVersion regexUnicodeVersion) : IGlobalOptions, IEquatable + Text.Json.CodeGeneration.GeneratedRegexUnicodeVersion regexUnicodeVersion, + int regexMatchTimeoutMilliseconds) : IGlobalOptions, IEquatable { public IVocabulary FallbackVocabulary { get; } = fallbackVocabulary; @@ -416,6 +428,8 @@ private class GlobalOptions( public Text.Json.CodeGeneration.GeneratedRegexUnicodeVersion RegexUnicodeVersion { get; } = regexUnicodeVersion; + public int RegexMatchTimeoutMilliseconds { get; } = regexMatchTimeoutMilliseconds; + public ILanguageProvider CreateLanguageProvider(string? defaultNamespace, IReadOnlyList namedTypes, bool emitEvaluator) { var mappedNamedTypes = new CSharpLanguageProvider.NamedType[namedTypes.Count]; @@ -451,7 +465,8 @@ other is not null && EmitUnions == other.EmitUnions && RegexEngine == other.RegexEngine && RegexEdition == other.RegexEdition && - RegexUnicodeVersion == other.RegexUnicodeVersion; + RegexUnicodeVersion == other.RegexUnicodeVersion && + RegexMatchTimeoutMilliseconds == other.RegexMatchTimeoutMilliseconds; } public override bool Equals(object? obj) => obj is GlobalOptions other && Equals(other); @@ -476,6 +491,7 @@ public override int GetHashCode() hash.Add(RegexEngine); hash.Add(RegexEdition); hash.Add(RegexUnicodeVersion); + hash.Add(RegexMatchTimeoutMilliseconds); return hash.ToHashCode(); } @@ -540,7 +556,8 @@ private CSharpLanguageProvider.Options MapOptions(string? defaultNamespace, CSha storeFilesAsStrings: true, regexEngine: RegexEngine, regexEdition: RegexEdition, - regexUnicodeVersion: RegexUnicodeVersion); + regexUnicodeVersion: RegexUnicodeVersion, + regexMatchTimeoutMilliseconds: RegexMatchTimeoutMilliseconds); return options; } diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/JsonSchema/Internal/JsonSchemaEvaluation.String.cs b/src/Corvus.Text.Json/Corvus/Text/Json/JsonSchema/Internal/JsonSchemaEvaluation.String.cs index ebc342d3944..6697e00863b 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/JsonSchema/Internal/JsonSchemaEvaluation.String.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/JsonSchema/Internal/JsonSchemaEvaluation.String.cs @@ -189,9 +189,9 @@ public static bool MatchRegularExpression(ReadOnlySpan value, Regex regula try { - JsonReaderHelper.TryGetTextFromUtf8(value, transcodedValue, out int written); - - if (!regularExpression.IsMatch(transcodedValue.Slice(0, written))) + // Text that is not UTF-8 matches no pattern. + if (!JsonReaderHelper.TryGetTextFromUtf8(value, transcodedValue, out int written) || + !regularExpression.IsMatch(transcodedValue.Slice(0, written))) { context.EvaluatedKeyword(false, originalExpressionString, messageProvider: ExpectedStringMatchesRegularExpression, keyword); return false; @@ -209,8 +209,8 @@ public static bool MatchRegularExpression(ReadOnlySpan value, Regex regula } #else // We pay for a conversion to string because netstandard does not support regular expressions - // from Span - if (!regularExpression.IsMatch(JsonReaderHelper.GetTextFromUtf8(value))) + // from Span. Text that is not UTF-8 matches no pattern. + if (!JsonWriterHelper.IsValidUtf8String(value) || !regularExpression.IsMatch(JsonReaderHelper.GetTextFromUtf8(value))) { context.EvaluatedKeyword(false, originalExpressionString, messageProvider: ExpectedStringMatchesRegularExpression, keyword); return false; @@ -238,9 +238,9 @@ public static bool MatchRegularExpression(ReadOnlySpan value, Regex regula try { - JsonReaderHelper.TryGetTextFromUtf8(value, transcodedValue, out int written); - - return regularExpression.IsMatch(transcodedValue.Slice(0, written)); + // Text that is not UTF-8 matches no pattern. + return JsonReaderHelper.TryGetTextFromUtf8(value, transcodedValue, out int written) && + regularExpression.IsMatch(transcodedValue.Slice(0, written)); } finally { @@ -251,8 +251,8 @@ public static bool MatchRegularExpression(ReadOnlySpan value, Regex regula } #else // We pay for a conversion to string because netstandard does not support regular expressions - // from Span - return regularExpression.IsMatch(JsonReaderHelper.GetTextFromUtf8(value)); + // from Span. Text that is not UTF-8 matches no pattern. + return JsonWriterHelper.IsValidUtf8String(value) && regularExpression.IsMatch(JsonReaderHelper.GetTextFromUtf8(value)); #endif } @@ -1874,9 +1874,10 @@ internal static bool MatchDecodedHostname(ReadOnlySpan value) /// if the value is a valid email address; otherwise, . internal static bool MatchEmail(ReadOnlySpan value) { - if (value.Length > 320 || value.Length < 3) + // There is no limit on the address as a whole, or on its local part: only the domain has one (253 characters, + // as a host name). The other ports limit only the domain too (#1029). + if (value.Length < 3) { - // The maximum length of an email address is 320 characters (RFC 5321). return false; } @@ -2108,9 +2109,11 @@ internal static bool MatchHostname(ReadOnlySpan value) [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool MatchIdnEmail(ReadOnlySpan value) { - if (value.Length > 320 || value.Length < 3) + // There is no limit on the address as a whole, or on its local part: only the domain has one, the limit of a + // host name (253 characters as A-labels), which a domain of U-labels can meet with more than 320 bytes of UTF-8 + // in the address. The other ports limit only the domain too (#1029). + if (value.Length < 3) { - // The maximum length of an email address is 320 characters (RFC 5321). return false; } @@ -2612,11 +2615,7 @@ private static int PunycodeAdapt(int delta, int numPoints, bool firstTime) private static bool MatchEmailLocalPart(ReadOnlySpan segment) { - if (segment.Length > 64) - { - return false; - } - + // No limit on the length of the local part, as in the other ports (#1029). // Skip an opening comment if (segment[0] == (byte)'(') { @@ -2689,11 +2688,7 @@ private static bool MatchEmailLocalPart(ReadOnlySpan segment) private static bool MatchEmailLocalPartUnicode(ReadOnlySpan segment) { - if (segment.Length > 64) - { - return false; - } - + // No limit on the length of the local part, as in the other ports (#1029). // Skip an opening comment if (segment[0] == (byte)'(') { diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescape.cs b/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescape.cs index 73fbcc9412b..a3ef3223e89 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescape.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescape.cs @@ -53,10 +53,48 @@ internal static bool TryUnescape(ReadOnlySpan source, Span destinati return TryUnescape(source, destination, idx, out written); } + /// + /// Unescapes text that may hold an escape of half of a surrogate pair with no other half (such as \ud800), + /// which the parser accepts. Such a code unit is written as its generalized UTF-8 bytes (\ud800 as + /// ED A0 80), which are not UTF-8, so the result reads as the same text with those bytes raw would. Every + /// other escape is unescaped as does it. + /// + /// The escaped text, with at least one escape. + /// The destination, at least as long as . + /// The number of bytes written. + internal static void UnescapeToGeneralizedUtf8(ReadOnlySpan source, Span destination, out int written) + { + Debug.Assert(destination.Length >= source.Length); + + int idx = source.IndexOf(JsonConstants.BackSlash); + Debug.Assert(idx >= 0); + + bool result = TryUnescape(source, destination, idx, out written, generalizeLoneSurrogates: true); + Debug.Assert(result); + } + + /// + /// , given the index of the first + /// escape. + /// + /// The escaped text. + /// The destination, at least as long as . + /// The index of the first backslash in . + /// The number of bytes written. + internal static void UnescapeToGeneralizedUtf8(ReadOnlySpan source, Span destination, int idx, out int written) + { + Debug.Assert(idx >= 0 && idx < source.Length); + Debug.Assert(source[idx] == JsonConstants.BackSlash); + Debug.Assert(destination.Length >= source.Length); + + bool result = TryUnescape(source, destination, idx, out written, generalizeLoneSurrogates: true); + Debug.Assert(result); + } + /// /// Used when writing to buffers not guaranteed to fit the unescaped result. /// - private static bool TryUnescape(ReadOnlySpan source, Span destination, int idx, out int written) + private static bool TryUnescape(ReadOnlySpan source, Span destination, int idx, out int written, bool generalizeLoneSurrogates = false) { Debug.Assert(idx >= 0 && idx < source.Length); Debug.Assert(source[idx] == JsonConstants.BackSlash); @@ -129,6 +167,12 @@ private static bool TryUnescape(ReadOnlySpan source, Span destinatio // The first hex value cannot be a low surrogate. if (scalar >= JsonConstants.LowSurrogateStartValue) { + if (generalizeLoneSurrogates) + { + WriteGeneralizedUtf8(scalar, destination, ref written); + break; + } + ThrowHelper.ThrowInvalidOperationException_ReadInvalidUTF16(scalar); } @@ -137,6 +181,12 @@ private static bool TryUnescape(ReadOnlySpan source, Span destinatio // We must have a low surrogate following a high surrogate. if (source.Length < idx + 7 || source[idx + 1] != '\\' || source[idx + 2] != 'u') { + if (generalizeLoneSurrogates) + { + WriteGeneralizedUtf8(scalar, destination, ref written); + break; + } + ThrowHelper.ThrowInvalidOperationException_ReadIncompleteUTF16(); } @@ -145,14 +195,22 @@ private static bool TryUnescape(ReadOnlySpan source, Span destinatio result = Utf8Parser.TryParse(source.Slice(idx + 3, 4), out int lowSurrogate, out bytesConsumed, 'x'); Debug.Assert(result); Debug.Assert(bytesConsumed == 4); - idx += 6; // If the first hex value is a high surrogate, the next one must be a low surrogate. if (!JsonHelpers.IsInRangeInclusive((uint)lowSurrogate, JsonConstants.LowSurrogateStartValue, JsonConstants.LowSurrogateEndValue)) { + if (generalizeLoneSurrogates) + { + // The next escape is not consumed: it is unescaped on its own (it may begin a pair). + WriteGeneralizedUtf8(scalar, destination, ref written); + break; + } + ThrowHelper.ThrowInvalidOperationException_ReadInvalidUTF16(lowSurrogate); } + idx += 6; + // To find the unicode scalar: // (0x400 * (High surrogate - 0xD800)) + Low surrogate - 0xDC00 + 0x10000 scalar = (JsonConstants.BitShiftBy10 * (scalar - JsonConstants.HighSurrogateStartValue)) @@ -231,4 +289,15 @@ private static bool TryUnescape(ReadOnlySpan source, Span destinatio DestinationTooShort: return false; } + + /// + /// Writes a lone surrogate code unit as the three bytes UTF-8 would give it as a scalar (generalized UTF-8). The + /// destination always has room: the escape it replaces is six bytes. + /// + private static void WriteGeneralizedUtf8(int codeUnit, Span destination, ref int written) + { + destination[written++] = (byte)(0xE0 | (codeUnit >> 12)); + destination[written++] = (byte)(0x80 | ((codeUnit >> 6) & 0x3F)); + destination[written++] = (byte)(0x80 | (codeUnit & 0x3F)); + } } \ No newline at end of file diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescaping.cs b/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescaping.cs index 0ce9f9b19c5..b5de13def20 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescaping.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/Reader/JsonReaderHelper.Unescaping.cs @@ -72,9 +72,13 @@ public static string GetUnescapedString(ReadOnlySpan utf8Source) return utf8String; } + // The comparisons unescape an escape of half of a surrogate pair as its generalized UTF-8 bytes rather than + // throwing (see UnescapeToGeneralizedUtf8): such text is then equal to the same text and to nothing else, as the + // same bytes raw are. Callers check the lengths of the whole texts against MaxExpansionFactorWhileEscaping, and + // pass what follows a common prefix, which keeps only the first of the two bounds. public static bool UnescapeAndCompare(ReadOnlySpan utf8Source, ReadOnlySpan other) { - Debug.Assert(utf8Source.Length >= other.Length && utf8Source.Length / JsonConstants.MaxExpansionFactorWhileEscaping <= other.Length); + Debug.Assert(utf8Source.Length >= other.Length); byte[]? unescapedArray = null; @@ -82,7 +86,7 @@ public static bool UnescapeAndCompare(ReadOnlySpan utf8Source, ReadOnlySpa stackalloc byte[JsonConstants.StackallocByteThreshold] : (unescapedArray = ArrayPool.Shared.Rent(utf8Source.Length)); - Unescape(utf8Source, utf8Unescaped, 0, out int written); + UnescapeToGeneralizedUtf8(utf8Source, utf8Unescaped, 0, out int written); Debug.Assert(written > 0); utf8Unescaped = utf8Unescaped.Slice(0, written); @@ -102,7 +106,7 @@ public static bool UnescapeAndCompare(ReadOnlySpan utf8Source, ReadOnlySpa public static bool UnescapeAndCompare(ReadOnlySequence utf8Source, ReadOnlySpan other) { Debug.Assert(!utf8Source.IsSingleSegment); - Debug.Assert(utf8Source.Length >= other.Length && utf8Source.Length / JsonConstants.MaxExpansionFactorWhileEscaping <= other.Length); + Debug.Assert(utf8Source.Length >= other.Length); byte[]? escapedArray = null; byte[]? unescapedArray = null; @@ -120,7 +124,7 @@ public static bool UnescapeAndCompare(ReadOnlySequence utf8Source, ReadOnl utf8Source.CopyTo(utf8Escaped); utf8Escaped = utf8Escaped.Slice(0, length); - Unescape(utf8Escaped, utf8Unescaped, 0, out int written); + UnescapeToGeneralizedUtf8(utf8Escaped, utf8Unescaped, 0, out int written); Debug.Assert(written > 0); utf8Unescaped = utf8Unescaped.Slice(0, written); @@ -159,11 +163,11 @@ public static bool UnescapeAndCompareBothInputs(ReadOnlySpan utf8Source1, stackalloc byte[JsonConstants.StackallocByteThreshold] : (unescapedArray2 = ArrayPool.Shared.Rent(utf8Source2.Length)); - Unescape(utf8Source1, utf8Unescaped1, index1, out int written); + UnescapeToGeneralizedUtf8(utf8Source1, utf8Unescaped1, index1, out int written); utf8Unescaped1 = utf8Unescaped1.Slice(0, written); Debug.Assert(!utf8Unescaped1.IsEmpty); - Unescape(utf8Source2, utf8Unescaped2, index2, out written); + UnescapeToGeneralizedUtf8(utf8Source2, utf8Unescaped2, index2, out written); utf8Unescaped2 = utf8Unescaped2.Slice(0, written); Debug.Assert(!utf8Unescaped2.IsEmpty); diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/CodeGeneration/IlSchemaEmitter.cs b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/CodeGeneration/IlSchemaEmitter.cs index aa15e3468fd..466ec79a1c8 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/CodeGeneration/IlSchemaEmitter.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/CodeGeneration/IlSchemaEmitter.cs @@ -96,6 +96,7 @@ internal sealed class IlSchemaEmitter : ISchemaEmitter private static readonly MethodInfo GenUniqueItems = Helper(nameof(Evaluator.GenUniqueItems)); private static readonly MethodInfo GenStringBytes = Helper(nameof(Evaluator.GenStringBytes)); private static readonly MethodInfo GenStringLengthCounted = Helper(nameof(Evaluator.GenStringLengthCounted)); + private static readonly MethodInfo GenIsUtf8 = Helper(nameof(Evaluator.GenIsUtf8)); private static readonly MethodInfo GenIsInteger = Helper(nameof(Evaluator.GenIsInteger)); private static readonly MethodInfo GenStringSet = Helper(nameof(Evaluator.GenStringSet)); private static readonly MethodInfo GenStringConst = Helper(nameof(Evaluator.GenStringConst)); @@ -1452,6 +1453,12 @@ public void FailUnlessStringLength(int minLength, int maxLength) il.Emit(OpCodes.Blt, counted); } + // The byte length decides it, for text that is UTF-8 (Evaluator.IsUtf8). + il.Emit(OpCodes.Ldarg_0); + il.Emit(OpCodes.Ldarg_1); + il.Emit(OpCodes.Ldloc, this.value!); + il.Emit(OpCodes.Call, GenIsUtf8); + il.Emit(OpCodes.Brfalse, this.fail); il.Emit(OpCodes.Br, within); this.Mark(counted); il.Emit(OpCodes.Ldarg_0); diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/FusedObjects.cs b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/FusedObjects.cs index 37aeddcc740..8d7e90d8983 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/FusedObjects.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/FusedObjects.cs @@ -625,7 +625,7 @@ int NameBit(byte[] name) { foreach (FusedAbsentPattern pattern in absent) { - if (!pattern.Matcher.IsMatch(names[e])) + if (!pattern.Matcher.IsMatch(names[e], knownUtf8: false)) { continue; } @@ -679,7 +679,7 @@ int NameBit(byte[] name) { foreach (PatternPropertyEntry pattern in patterns) { - if (pattern.Matcher.IsMatch(name)) + if (pattern.Matcher.IsMatch(name, knownUtf8: false)) { matched = true; applications.Add(Application(nodes, c, pattern.Schema)); diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/SchemaNode.cs b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/SchemaNode.cs index 8d4027e59bb..3450ac0986d 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/SchemaNode.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Compilation/SchemaNode.cs @@ -718,9 +718,24 @@ private static PatternMatcher CreateRegex(string ecmaPattern, EcmaRegex compiled } #endif + /// Whether text matches the pattern. + /// The text. + /// Whether the text is known to be UTF-8: the parser found it all ASCII, or it has been checked. + /// when the text matches. + /// + /// Text that is not UTF-8 matches no pattern (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). It + /// is checked here, unless it is known to be UTF-8. + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool IsMatch(ReadOnlySpan utf8Value) + public bool IsMatch(ReadOnlySpan utf8Value, bool knownUtf8) { +#if !STJ + if (!knownUtf8 && !Evaluation.Evaluator.IsUtf8(utf8Value)) + { + return false; + } +#endif + return this.kind switch { Kind.Noop => true, diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/EvaluationState.cs b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/EvaluationState.cs index d9ba6255008..0b650ffb56c 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/EvaluationState.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/EvaluationState.cs @@ -288,16 +288,16 @@ public int NextIndex(ref EvaluationState state, IJsonDocument doc, int index) public UnescapedUtf8JsonString GetString(ref EvaluationState state, IJsonDocument doc, int index) { - // Escaped strings are rare: unescape through the document; otherwise wrap the raw text without renting. + // Escaped strings are rare: unescape out of line; otherwise wrap the raw text without renting. return this.IsEscaped(ref state, doc, index) - ? doc.GetUtf8JsonString(index, JsonTokenType.String) + ? EscapedText.Unescape(this.RawValue(ref state, doc, index, out _)) : new UnescapedUtf8JsonString(this.RawValueMemory(ref state, doc, index)); } public UnescapedUtf8JsonString GetPropertyName(ref EvaluationState state, IJsonDocument doc, int valueIndex) { return this.IsEscaped(ref state, doc, valueIndex - RowSize) - ? doc.GetPropertyNameUnescaped(valueIndex) + ? EscapedText.Unescape(this.RawValue(ref state, doc, valueIndex - RowSize, out _)) : new UnescapedUtf8JsonString(this.RawValueMemory(ref state, doc, valueIndex - RowSize)); } @@ -371,9 +371,45 @@ public int PropertyNameLocationUnchecked(ref EvaluationState state, IJsonDocumen public int NextIndexUnchecked(ref EvaluationState state, IJsonDocument doc, int index) => this.NextIndex(ref state, doc, index); - public UnescapedUtf8JsonString GetString(ref EvaluationState state, IJsonDocument doc, int index) => doc.GetUtf8JsonString(index, JsonTokenType.String); + public UnescapedUtf8JsonString GetString(ref EvaluationState state, IJsonDocument doc, int index) => EscapedText.GetString(doc, index); - public UnescapedUtf8JsonString GetPropertyName(ref EvaluationState state, IJsonDocument doc, int valueIndex) => doc.GetPropertyNameUnescaped(valueIndex); + public UnescapedUtf8JsonString GetPropertyName(ref EvaluationState state, IJsonDocument doc, int valueIndex) => EscapedText.GetPropertyName(doc, valueIndex); +} + +/// +/// The unescaping of a string's text for its keywords. The parser accepts an escape of half of a surrogate pair with +/// no other half (such as \ud800), and the document's own unescaping throws for one. Here it is read as its +/// generalized UTF-8 bytes, which are not UTF-8, so that a keyword reads it as it reads the same bytes raw: those +/// that read characters report the string not valid, and those that compare text find it equal to no well-formed +/// text (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). Well-formed text unescapes as it does +/// through the document. +/// +internal static class EscapedText +{ + /// Gets the text of a string value through the document interface. + public static UnescapedUtf8JsonString GetString(IJsonDocument doc, int index) + { + return doc.ValueIsEscaped(index, isPropertyName: false) + ? Unescape(doc.GetRawSimpleValue(index, includeQuotes: false).Span) + : doc.GetUtf8JsonString(index, JsonTokenType.String); + } + + /// Gets a property's name, for the index of its value, through the document interface. + public static UnescapedUtf8JsonString GetPropertyName(IJsonDocument doc, int valueIndex) + { + return doc.ValueIsEscaped(valueIndex, isPropertyName: true) + ? Unescape(doc.GetPropertyNameRaw(valueIndex, includeQuotes: false).Span) + : doc.GetPropertyNameUnescaped(valueIndex); + } + + /// Unescapes a string's raw text, which has at least one escape, into a rented buffer. + [MethodImpl(MethodImplOptions.NoInlining)] + public static UnescapedUtf8JsonString Unescape(ReadOnlySpan raw) + { + byte[] rented = ArrayPool.Shared.Rent(raw.Length); + JsonReaderHelper.UnescapeToGeneralizedUtf8(raw, rented, out int written); + return new UnescapedUtf8JsonString(rented.AsMemory(0, written), rented); + } } /// @@ -505,7 +541,7 @@ internal static class Providers return System.Buffers.Text.Utf8Formatter.TryFormat(ctx.ItemIndex, buffer, out written); } - using UnescapedUtf8JsonString name = ctx.Document!.GetPropertyNameUnescaped(ctx.PropertyValueIndex); + using UnescapedUtf8JsonString name = EscapedText.GetPropertyName(ctx.Document!, ctx.PropertyValueIndex); return Utf8JsonPointer.TryEncodeSegment(name.Span, buffer, out written); }; diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.Generated.cs b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.Generated.cs index 45f718dd86f..4beddeb9666 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.Generated.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.Generated.cs @@ -395,6 +395,13 @@ internal static bool GenStringLengthCounted(ref EvaluationState state, IJsonDocu : LengthWithin(raw, minLength, maxLength); } + /// + /// Whether a string value's text, unescaped and not all ASCII, is UTF-8 (see ): for the values + /// whose byte length decides their length. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + internal static bool GenIsUtf8(ref EvaluationState state, IJsonDocument doc, int index) => IsUtf8(default(RawAccess).RawValue(ref state, doc, index, out _)); + /// Whether a property's name is a given name, for the names generated code does not compare by words (escaped, or at the very end of the text). [MethodImpl(MethodImplOptions.NoInlining)] internal static bool GenNameEquals(ref EvaluationState state, IJsonDocument doc, int valueIndex, byte[] name) @@ -437,11 +444,11 @@ internal static bool GenPattern(ref EvaluationState state, IJsonDocument doc, in ReadOnlySpan raw = default(RawAccess).RawValue(ref state, doc, index, out bool escaped); if (!escaped) { - return matcher.IsMatch(raw); + return matcher.IsMatch(raw, default(RawAccess).IsAsciiText(ref state, doc, index)); } using UnescapedUtf8JsonString text = StringValue(ref state, doc, index); - return matcher.IsMatch(text.Span); + return matcher.IsMatch(text.Span, knownUtf8: false); } /// Whether a value is a string in a set. diff --git a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.cs b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.cs index 953b7161adb..b9f3e341252 100644 --- a/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.cs +++ b/src/Corvus.Text.Json/Corvus/Text/Json/RuntimeEvaluator/Evaluation/Evaluator.cs @@ -216,6 +216,14 @@ private static UnescapedUtf8JsonString StringValue(ref EvaluationState return default(TAccess).GetString(ref state, doc, index); } + /// Whether the parser found a property's name, for the index of its value, unescaped and all ASCII. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool NameIsAscii(ref EvaluationState state, IJsonDocument doc, int valueIndex) + where TAccess : struct, IDocumentAccess + { + return default(TAccess).IsAsciiText(ref state, doc, valueIndex - RowSize); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static UnescapedUtf8JsonString PropertyName(ref EvaluationState state, IJsonDocument doc, int valueIndex) where TAccess : struct, IDocumentAccess @@ -1291,11 +1299,11 @@ private static bool MatchesName(PatternMatcher matcher, ref EvaluationS ReadOnlySpan raw = default(TAccess).PropertyNameRawUnchecked(ref state, doc, valueIndex, out bool escaped); if (!escaped) { - return matcher.IsMatch(raw); + return matcher.IsMatch(raw, NameIsAscii(ref state, doc, valueIndex)); } using UnescapedUtf8JsonString name = PropertyName(ref state, doc, valueIndex); - return matcher.IsMatch(name.Span); + return matcher.IsMatch(name.Span, knownUtf8: false); } /// A value against an in-place resolution: a token-type test, a string set or const, or the child. @@ -1368,16 +1376,17 @@ private static bool StringLengthWithin(in StrictEntry entry, ref Evalua return EscapedStringLengthWithin(entry.MinLength, entry.MaxLength, ref state, doc, index); } + // An unescaped string the parser found all ASCII has one character to a byte: its length is exact. int bytes = raw.Length; - if ((entry.MaxLength < 0 || bytes <= entry.MaxLength) && (entry.MinLength < 0 || ((bytes + 3) >> 2) >= entry.MinLength)) + if (default(TAccess).IsAsciiText(ref state, doc, index)) { - return true; + return (entry.MaxLength < 0 || bytes <= entry.MaxLength) && (entry.MinLength < 0 || bytes >= entry.MinLength); } - // An unescaped string the parser found all ASCII has one character to a byte: its length is exact. - if (default(TAccess).IsAsciiText(ref state, doc, index)) + // Other text is within the bounds when its byte length decides it, and it is UTF-8 (see IsUtf8). + if ((entry.MaxLength < 0 || bytes <= entry.MaxLength) && (entry.MinLength < 0 || ((bytes + 3) >> 2) >= entry.MinLength)) { - return (entry.MaxLength < 0 || bytes <= entry.MaxLength) && (entry.MinLength < 0 || bytes >= entry.MinLength); + return IsUtf8(raw); } return LengthWithin(raw, entry.MinLength, entry.MaxLength); @@ -1391,7 +1400,10 @@ private static bool EscapedStringLengthWithin(int minLength, int maxLen return LengthWithin(s.Span, minLength, maxLength); } - /// Whether a string's length in runes is within the bounds (-1 for an absent bound). + /// + /// Whether a string's length in runes is within the bounds (-1 for an absent bound). Text that is not UTF-8 is not + /// (see ). + /// private static bool LengthWithin(ReadOnlySpan value, int minLength, int maxLength) { int bytes = value.Length; @@ -1400,8 +1412,37 @@ private static bool LengthWithin(ReadOnlySpan value, int minLength, int ma return false; } - int runes = JsonElementHelpers.CountRunes(value); - return (minLength < 0 || runes >= minLength) && (maxLength < 0 || runes <= maxLength); + int runes = RuneCountIfUtf8(value); + return runes >= 0 && (minLength < 0 || runes >= minLength) && (maxLength < 0 || runes <= maxLength); + } + + /// The number of runes in text, or -1 when it is not UTF-8. + private static int RuneCountIfUtf8(ReadOnlySpan value) + { + return IsUtf8(value) ? RuneCountOfUtf8(value) : -1; + } + + /// The number of runes in text that is UTF-8: one for each byte that does not continue a sequence. + private static int RuneCountOfUtf8(ReadOnlySpan value) + { +#if NET + // Most text is ASCII (escaped text is not flagged as such), checked vectorised. + if (System.Text.Ascii.IsValid(value)) + { + return value.Length; + } +#endif + + int continuation = 0; + foreach (byte b in value) + { + if ((b & 0xC0) == 0x80) + { + continuation++; + } + } + + return value.Length - continuation; } /// The name lookup for an escaped property name, out of line: escapes are rare and the loop is register-bound. @@ -1548,7 +1589,7 @@ private static bool ApplyFusedUnknown(FusedObject f, scoped ReadOnlySpa FusedAbsentPattern[] absent = f.AbsentPatterns; for (int p = 0; p < absent.Length; p++) { - if (!failed[absent[p].Condition] && absent[p].Matcher.IsMatch(nameSpan)) + if (!failed[absent[p].Condition] && absent[p].Matcher.IsMatch(nameSpan, NameIsAscii(ref state, doc, valueIndex))) { failed[absent[p].Condition] = true; } @@ -1617,30 +1658,30 @@ private static void ApplyValueTests(FusedEntry entry, JsonTokenType val ReadOnlySpan raw = default(TAccess).RawValue(ref state, doc, valueIndex, out bool escaped); if (!escaped) { - TestValueKey(entry, Discriminator.StringTag, raw, failed); + TestValueKey(entry, Discriminator.StringTag, raw, default(TAccess).IsAsciiText(ref state, doc, valueIndex), failed); return; } using UnescapedUtf8JsonString text = StringValue(ref state, doc, valueIndex); - TestValueKey(entry, Discriminator.StringTag, text.Span, failed); + TestValueKey(entry, Discriminator.StringTag, text.Span, ascii: false, failed); return; } case JsonTokenType.True: - TestValueKey(entry, Discriminator.BooleanTag, "true"u8, failed); + TestValueKey(entry, Discriminator.BooleanTag, "true"u8, ascii: true, failed); return; case JsonTokenType.False: - TestValueKey(entry, Discriminator.BooleanTag, "false"u8, failed); + TestValueKey(entry, Discriminator.BooleanTag, "false"u8, ascii: true, failed); return; case JsonTokenType.Null: - TestValueKey(entry, Discriminator.NullTag, "null"u8, failed); + TestValueKey(entry, Discriminator.NullTag, "null"u8, ascii: true, failed); return; case JsonTokenType.Number: { ReadOnlySpan rawNumber = default(TAccess).RawValue(ref state, doc, valueIndex); if (IsCanonicalInteger(rawNumber)) { - TestValueKey(entry, Discriminator.NumberTag, rawNumber, failed); + TestValueKey(entry, Discriminator.NumberTag, rawNumber, ascii: true, failed); return; } @@ -1684,7 +1725,7 @@ private static void ApplyValueTests(FusedEntry entry, JsonTokenType val } /// One lookup of the tagged value decides every keyed test; the pattern tests run on the string. - private static void TestValueKey(FusedEntry entry, byte tag, ReadOnlySpan value, Span failed) + private static void TestValueKey(FusedEntry entry, byte tag, ReadOnlySpan value, bool ascii, Span failed) { FusedValueTest[] keyed = entry.KeyedTests; if (keyed.Length > 0) @@ -1716,7 +1757,7 @@ private static void TestValueKey(FusedEntry entry, byte tag, ReadOnlySpan for (int t = 0; t < patterns.Length; t++) { FusedValueTest test = patterns[t]; - bool passes = tag == Discriminator.StringTag ? test.Pattern!.IsMatch(value) : !test.RequiresString; + bool passes = tag == Discriminator.StringTag ? test.Pattern!.IsMatch(value, ascii) : !test.RequiresString; if (!passes) { failed[test.Condition] = true; @@ -1748,7 +1789,7 @@ private static bool ResolveUnknownName(FusedContributor contributor, sc for (int p = 0; p < patterns.Length; p++) { PatternPropertyEntry pattern = patterns[p]; - if (pattern.Matcher.IsMatch(name)) + if (pattern.Matcher.IsMatch(name, NameIsAscii(ref state, doc, valueIndex))) { covered = true; SchemaNode target = nodes[pattern.Schema.FastNode]; @@ -2176,7 +2217,7 @@ private static bool EvalObjectPlanProperty(SchemaNode node, int entryIn for (int p = 0; p < patternProperties.Length; p++) { PatternPropertyEntry pp = patternProperties[p]; - if (pp.Matcher.IsMatch(name)) + if (pp.Matcher.IsMatch(name, NameIsAscii(ref state, doc, valueIndex))) { matched = true; if (!EvalChildFast(state.Nodes[pp.Schema.FastNode], doc, valueIndex, ref state)) @@ -2904,6 +2945,10 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO { bool ok = true; + // Text that is not UTF-8 fails every keyword that reads its characters (see EscapedText); text the parser + // found all ASCII is UTF-8, and is not checked. + bool wellFormed = ascii || !ReadsCharacters(node) || IsUtf8(value); + if (node.MinLength >= 0 || node.MaxLength >= 0) { // A rune is one to four bytes, so the byte length bounds the rune count both ways; only values inside @@ -2913,7 +2958,7 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO if (node.MinLength >= 0) { bool m; - if (byteLength < node.MinLength) + if (!wellFormed || byteLength < node.MinLength) { m = false; } @@ -2925,7 +2970,7 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO { if (runeCount < 0) { - runeCount = JsonElementHelpers.CountRunes(value); + runeCount = RuneCountOfUtf8(value); } m = runeCount >= node.MinLength; @@ -2950,7 +2995,11 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO if (node.MaxLength >= 0) { bool m; - if (byteLength <= node.MaxLength) + if (!wellFormed) + { + m = false; + } + else if (byteLength <= node.MaxLength) { m = true; } @@ -2962,7 +3011,7 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO { if (runeCount < 0) { - runeCount = JsonElementHelpers.CountRunes(value); + runeCount = RuneCountOfUtf8(value); } m = runeCount <= node.MaxLength; @@ -2987,7 +3036,7 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO if (node.Pattern is PatternMatcher pattern) { - bool m = pattern.IsMatch(value); + bool m = wellFormed && pattern.IsMatch(value, knownUtf8: true); if (default(TMode).Collecting) { state.Collector!.EvaluatedKeyword(m, pattern.Source, JsonSchemaEvaluation.ExpectedStringMatchesRegularExpression, "pattern"u8); @@ -3006,7 +3055,7 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO if (node.AssertFormat && node.Format != FormatKind.None && !FormatKinds.IsNumeric(node.Format)) { - bool m = MatchesFormat(node.Format, node.Dialect, value, ref state); + bool m = wellFormed && MatchesFormat(node.Format, node.Dialect, value, ref state); if (node.WarnFormat) { if (default(TMode).Collecting) @@ -3035,7 +3084,7 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO if (node.AssertContent) { JsonSchemaContext scratch = default; - bool m = node.Content switch + bool m = wellFormed && node.Content switch { ContentKind.Base64 => JsonSchemaEvaluation.MatchBase64String(value, ContentEncodingKeyword, ref scratch), ContentKind.Json => JsonSchemaEvaluation.MatchJsonContent(value, ContentMediaTypeKeyword, ref scratch), @@ -3070,6 +3119,20 @@ private static bool EvalStringCore(SchemaNode node, scoped ReadO return ok; } + /// Whether a string node has a keyword that reads the string's characters. + private static bool ReadsCharacters(SchemaNode node) => + node.MinLength >= 0 || node.MaxLength >= 0 || node.Pattern is not null || node.AssertContent + || (node.AssertFormat && node.Format != FormatKind.None); + + /// + /// Whether text is UTF-8. The parser accepts any bytes in a string, and an escape of half of a surrogate pair reads + /// as bytes that are not UTF-8 (see ): a keyword that reads the characters of such text + /// reports it not valid (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). Out of line: only text + /// that is not all ASCII is checked. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + internal static bool IsUtf8(scoped ReadOnlySpan value) => JsonWriterHelper.IsValidUtf8String(value); + private static bool MatchesFormat(FormatKind format, JsonSchemaDialect dialect, scoped ReadOnlySpan value, ref EvaluationState state) { if (FormatKinds.IsNumeric(format)) @@ -3339,7 +3402,7 @@ private static bool EvalObjectCore(SchemaNode node, IJsonDocumen for (int p = 0; p < patternProperties.Length; p++) { PatternPropertyEntry pp = patternProperties[p]; - if (pp.Matcher.IsMatch(nameSpan)) + if (pp.Matcher.IsMatch(nameSpan, NameIsAscii(ref state, doc, valueIndex))) { matched = true; MarkEvaluated(evaluated, propertyIndex); diff --git a/tests-v4/Corvus.Json.Specs.Tests/HandWritten/MalformedStringTests.cs b/tests-v4/Corvus.Json.Specs.Tests/HandWritten/MalformedStringTests.cs new file mode 100644 index 00000000000..1d31565fe63 --- /dev/null +++ b/tests-v4/Corvus.Json.Specs.Tests/HandWritten/MalformedStringTests.cs @@ -0,0 +1,146 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using System.Text; +using System.Text.Json; +using Corvus.Json; +using Corvus.Json.CodeGeneration.CSharp; +using Corvus.Json.Specs.Tests.Infrastructure; +using Drivers; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Json.Specs.Tests.HandWritten; + +/// +/// A string that is not well-formed text (an escape of half of a surrogate pair, or bytes that are not UTF-8) is +/// accepted when the document is parsed. Generated code reports it not valid against a keyword that reads its +/// characters, and never throws (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). +/// +[TestClass] +public class MalformedStringTests +{ + private static readonly Dictionary Malformed = new() + { + ["lone high surrogate escape"] = Encoding.UTF8.GetBytes("\"\\ud800\""), + ["lone high surrogate escape at the end"] = Encoding.UTF8.GetBytes("\"a\\ud83d\""), + ["lone low surrogate escape"] = Encoding.UTF8.GetBytes("\"\\udc00\""), + ["low surrogate escape after a character"] = Encoding.UTF8.GetBytes("\"a\\udc00\""), + ["high surrogate escape before a character"] = Encoding.UTF8.GetBytes("\"\\ud800x\""), + ["high surrogate escape before another escape"] = Encoding.UTF8.GetBytes("\"\\ud800\\u0061\""), + ["a surrogate encoded in UTF-8"] = [0x22, 0xED, 0xA0, 0x80, 0x22], + ["a lead byte without its continuation"] = [0x22, 0xC3, 0x28, 0x22], + ["a byte that is never UTF-8"] = [0x22, 0xFF, 0x22], + ["a byte that is never UTF-8 after an escape"] = [0x22, 0x5C, 0x6E, 0xFF, 0x22], + }; + + [TestMethod] + [DataRow("""{"pattern": "^.$"}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"pattern": "^.$"}""", false, GeneratedRegexEngine.DotNet)] + [DataRow("""{"pattern": "^(.)\\1?$"}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"pattern": "^(.)\\1?$"}""", false, GeneratedRegexEngine.DotNet)] + [DataRow("""{"minLength": 1}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"maxLength": 5}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"enum": ["a", "b"]}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"const": "a"}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"format": "email"}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"format": "idn-email"}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"format": "date"}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"format": "uri"}""", false, GeneratedRegexEngine.Ecma262)] + [DataRow("""{"type": "string"}""", true, GeneratedRegexEngine.Ecma262)] + public async Task AKeywordThatReadsAMalformedStringReportsItNotValid(string schema, bool expected, GeneratedRegexEngine regexEngine) + { + Type type = await GenerateType(schema, regexEngine); + AssertEveryInstance(type, static json => json, expected); + } + + [TestMethod] + [DataRow("""{"propertyNames": {"pattern": "^a"}}""", false)] + [DataRow("""{"propertyNames": {"maxLength": 3}}""", false)] + [DataRow("""{"patternProperties": {"^a": {}}, "additionalProperties": false}""", false)] + [DataRow("""{"properties": {"a": {}}, "additionalProperties": false}""", false)] + public async Task AKeywordThatReadsAMalformedPropertyNameReportsItNotValid(string schema, bool expected) + { + Type type = await GenerateType(schema, GeneratedRegexEngine.Ecma262); + AssertEveryInstance(type, static json => [.. "{"u8.ToArray(), .. json, .. ": 1}"u8.ToArray()], expected); + } + + [TestMethod] + public async Task PropertiesAloneNeverThrowsForAMalformedName() + { + // System.Text.Json unescapes a name it compares in a property lookup when the lengths allow a match, which + // throws for an escape of half of a surrogate pair; V4 then reports the object not valid. Otherwise the name + // matches no property, and the object is valid. Either way, validation gives a result. + Type type = await GenerateType("""{"properties": {"a": {}}}""", GeneratedRegexEngine.Ecma262); + foreach (KeyValuePair entry in Malformed) + { + string name = entry.Key; + byte[] json = entry.Value; + try + { + Validate(type, [.. "{"u8.ToArray(), .. json, .. ": 1}"u8.ToArray()]); + } + catch (Exception ex) + { + Assert.Fail($"{name}: {ex.GetType().Name}: {ex.Message}"); + } + } + } + + [TestMethod] + public async Task WellFormedTextIsReadAsItAlwaysWas() + { + Type type = await GenerateType("""{"pattern": "^.$", "minLength": 1, "maxLength": 1}""", GeneratedRegexEngine.Ecma262); + foreach (string json in new[] { "\"\u00e9\"", "\"\\u00e9\"", "\"\\ud83d\\ude00\"", "\"\ud83d\ude00\"" }) + { + Assert.IsTrue(Validate(type, Encoding.UTF8.GetBytes(json)), json); + } + } + + private static async Task GenerateType(string schema, GeneratedRegexEngine regexEngine) + { + using JsonSchemaBuilderDriver driver = DriverFactory.CreateDraft202012Driver(); + return await driver.GenerateTypeForVirtualFile( + schema, + "malformedString.json", + "MalformedString", + "Scenario", + validateFormat: true, + optionalAsNullable: false, + useImplicitOperatorString: false, + regexEngine: regexEngine); + } + + private static void AssertEveryInstance(Type type, Func wrap, bool expected) + { + var failures = new List(); + foreach (KeyValuePair entry in Malformed) + { + string name = entry.Key; + byte[] json = entry.Value; + try + { + if (Validate(type, wrap(json)) != expected) + { + failures.Add($"{name}: not {expected}"); + } + } + catch (Exception ex) + { + failures.Add($"{name}: {ex.GetType().Name}: {ex.Message}"); + } + } + + Assert.AreEqual(0, failures.Count, string.Join(Environment.NewLine, failures)); + } + + private static bool Validate(Type type, byte[] json) + { + using var doc = JsonDocument.Parse(json); + IJsonValue instance = JsonSchemaBuilderDriver.CreateInstance(type, doc.RootElement); + bool flag = instance.Validate(ValidationContext.ValidContext, ValidationLevel.Flag).IsValid; + bool detailed = instance.Validate(ValidationContext.ValidContext, ValidationLevel.Detailed).IsValid; + Assert.AreEqual(flag, detailed, "flag and detailed validation agree"); + return flag; + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.CodeGenerator.Tests/CliHelpTests.cs b/tests/Corvus.Text.Json.CodeGenerator.Tests/CliHelpTests.cs new file mode 100644 index 00000000000..9553fc34500 --- /dev/null +++ b/tests/Corvus.Text.Json.CodeGenerator.Tests/CliHelpTests.cs @@ -0,0 +1,46 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using System.Text.RegularExpressions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Text.Json.CodeGenerator.Tests; + +/// +/// The help of every command renders. Spectre.Console reads square brackets in a description as markup, so a +/// description with text such as [Flags] made corvusjson jsonschema --help fail with +/// "Could not find color or style 'Flags'". +/// +[TestClass] +public class CliHelpTests +{ + [TestMethod] + public async Task TheHelpOfEveryCommandRenders() + { + ProcessResult root = await CodeGeneratorRunner.RunAsync("--help"); + Assert.AreEqual(0, root.ExitCode, root.StandardOutput + root.StandardError); + + // Spectre.Console colours its output where it detects a terminal or a CI host (GitHub Actions among them), so + // the escape sequences are removed before the lines are read. + string[] commands = + [ + .. Regex.Replace(root.StandardOutput, "\u001b\\[[0-9;]*m", string.Empty) + .Split('\n') + .SkipWhile(l => !l.TrimStart().StartsWith("COMMANDS:", StringComparison.Ordinal)) + .Skip(1) + .Where(l => l.Length > 4 && l.StartsWith(" ", StringComparison.Ordinal) && char.IsLetter(l[4])) // a command's own line, not a wrapped description + .Select(l => l.Trim().Split(' ', 2)[0]) + .Distinct(StringComparer.Ordinal) + ]; + + Assert.IsTrue(commands.Contains("jsonschema"), string.Join(", ", commands)); + + foreach (string command in commands) + { + ProcessResult help = await CodeGeneratorRunner.RunAsync($"{command} --help"); + Assert.AreEqual(0, help.ExitCode, $"{command} --help: {help.StandardOutput}{help.StandardError}"); + Assert.IsFalse((help.StandardOutput + help.StandardError).Contains("Error:", StringComparison.Ordinal), $"{command} --help: {help.StandardOutput}{help.StandardError}"); + } + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.CodeGenerator.Tests/GenerateCommandTests.cs b/tests/Corvus.Text.Json.CodeGenerator.Tests/GenerateCommandTests.cs index a073c7ae3ed..e41ed5ccb10 100644 --- a/tests/Corvus.Text.Json.CodeGenerator.Tests/GenerateCommandTests.cs +++ b/tests/Corvus.Text.Json.CodeGenerator.Tests/GenerateCommandTests.cs @@ -396,6 +396,42 @@ public async Task Generate_WithARegexEditionAndUnicodeVersion_LoadsTheProgramWit StringAssert.Contains(code, "(global::Corvus.Ecma262.RegularExpressions.RegexEdition)0, (global::Corvus.Ecma262.RegularExpressions.RegexUnicodeVersion)13,"); } + [TestMethod] + [DataRow("V5", "250", "global::System.TimeSpan.FromMilliseconds(250)")] + [DataRow("V5", "-1", "global::System.Text.RegularExpressions.Regex.InfiniteMatchTimeout")] + [DataRow("V4", "250", "global::System.TimeSpan.FromMilliseconds(250)")] + public async Task Generate_WithARegexMatchTimeout_WritesItIntoTheGeneratedCode(string engine, string matchTimeout, string expected) + { + // https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1022 + string schema = CodeGeneratorRunner.GetFixturePath("Schemas", "regex-table-library.json"); + + ProcessResult result = await CodeGeneratorRunner.RunAsync( + $"jsonschema \"{schema}\" --rootNamespace T --outputPath \"{_outputDir}\" --engine {engine} --regexMatchTimeout {matchTimeout}"); + + Assert.AreEqual(0, result.ExitCode, result.StandardError); + string code = ReadAllGeneratedCode(_outputDir); + StringAssert.Contains(code, expected); + Assert.IsFalse(code.Contains("FromMilliseconds(1000)"), "The default timeout is not written when the options give another."); + if (engine == "V5") + { + StringAssert.Contains(code, $"RegexMatchTimeout = {expected},"); + } + } + + [TestMethod] + [DataRow("0")] + [DataRow("-2")] + public async Task Generate_WithARegexMatchTimeoutThatIsNotPositiveOrMinusOne_IsRefused(string matchTimeout) + { + string schema = CodeGeneratorRunner.GetFixturePath("Schemas", "regex-table-library.json"); + + ProcessResult result = await CodeGeneratorRunner.RunAsync( + $"jsonschema \"{schema}\" --rootNamespace T --outputPath \"{_outputDir}\" --regexMatchTimeout {matchTimeout}"); + + Assert.AreNotEqual(0, result.ExitCode); + StringAssert.Contains(result.StandardOutput + result.StandardError, "regexMatchTimeout"); + } + [TestMethod] public async Task Generate_FormatModeDisable_DisablesFormatEvenForDraft07() { diff --git a/tests/Corvus.Text.Json.Patch.Tests/Corvus.Text.Json.Patch.Tests.csproj b/tests/Corvus.Text.Json.Patch.Tests/Corvus.Text.Json.Patch.Tests.csproj index 9c8ec9fcca9..df4bced0173 100644 --- a/tests/Corvus.Text.Json.Patch.Tests/Corvus.Text.Json.Patch.Tests.csproj +++ b/tests/Corvus.Text.Json.Patch.Tests/Corvus.Text.Json.Patch.Tests.csproj @@ -8,6 +8,7 @@ + diff --git a/tests/Corvus.Text.Json.Patch.Tests/GeneratedTypePatchTests.cs b/tests/Corvus.Text.Json.Patch.Tests/GeneratedTypePatchTests.cs new file mode 100644 index 00000000000..9d9b639a23f --- /dev/null +++ b/tests/Corvus.Text.Json.Patch.Tests/GeneratedTypePatchTests.cs @@ -0,0 +1,99 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using Corvus.Text.Json.Patch; +using Corvus.Text.Json.Tests.GeneratedModels.Draft202012; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Text.Json.Patch.Tests; + +/// +/// A JSON Patch applies to the mutable element of a generated type +/// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/943). +/// +[TestClass] +public class GeneratedTypePatchTests +{ + private const string Json = """{"address":{"street":"1 High Street","city":"Bath"},"notes":"n"}"""; + + [TestMethod] + public void TryApplyPatch_AppliesThePatchToTheElement() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse(Json); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + using var patch = ParsedJsonDocument.Parse(""" + [ + { "op": "replace", "path": "/address/city", "value": "Bristol" }, + { "op": "remove", "path": "/notes" } + ] + """); + + NestedObject.Mutable root = builder.RootElement; + Assert.IsTrue(root.TryApplyPatch(patch.RootElement)); + + Assert.AreEqual("Bristol", (string)root.Address.City); + Assert.IsTrue(root.Notes.IsUndefined()); + Assert.AreEqual("""{"address":{"street":"1 High Street","city":"Bristol"}}""", builder.RootElement.ToString()); + } + + [TestMethod] + public void TryApplyPatch_AtTheRoot_GivesTheNewValue() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse(Json); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + using var patch = ParsedJsonDocument.Parse("""[{ "op": "replace", "path": "", "value": {"address":{"street":"2 Low Road"}} }]"""); + + NestedObject.Mutable root = builder.RootElement; + Assert.IsTrue(root.TryApplyPatch(patch.RootElement)); + + Assert.AreEqual("2 Low Road", (string)root.Address.Street); + } + + [TestMethod] + public void TryApplyPatch_ThatCannotApply_ReturnsFalse() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse(Json); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + using var patch = ParsedJsonDocument.Parse("""[{ "op": "test", "path": "/notes", "value": "other" }]"""); + + NestedObject.Mutable root = builder.RootElement; + Assert.IsFalse(root.TryApplyPatch(patch.RootElement)); + } + + [TestMethod] + public void TryValidateAndApplyPatch_RefusesADocumentThatIsNotAPatch() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse(Json); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + using var notAPatch = ParsedJsonDocument.Parse("""[{ "op": "frobnicate", "path": "/notes" }]"""); + using var patch = ParsedJsonDocument.Parse("""[{ "op": "add", "path": "/notes", "value": "added" }]"""); + + NestedObject.Mutable root = builder.RootElement; + Assert.IsFalse(root.TryValidateAndApplyPatch(notAPatch.RootElement)); + Assert.AreEqual("n", (string)root.Notes); + + Assert.IsTrue(root.TryValidateAndApplyPatch(patch.RootElement)); + Assert.AreEqual("added", (string)root.Notes); + } + + [TestMethod] + public void AMergePatchThatReplacesTheRoot_AppliesToAGeneratedTypesBuilder() + { + // The merge patch takes JsonElement.Mutable; replacing the root of a generated type's builder cast the + // builder to the wrong type. + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse(Json); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + using var patch = ParsedJsonDocument.Parse("""[1, 2]"""); + + JsonElement.Mutable root = JsonElement.Mutable.From(builder.RootElement); + JsonMergePatchExtensions.ApplyMergePatch(ref root, patch.RootElement); + + Assert.AreEqual("[1, 2]", builder.RootElement.ToString()); + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.RuntimeEvaluator.Tests/Unit/MalformedStringTests.cs b/tests/Corvus.Text.Json.RuntimeEvaluator.Tests/Unit/MalformedStringTests.cs new file mode 100644 index 00000000000..50eaede61f7 --- /dev/null +++ b/tests/Corvus.Text.Json.RuntimeEvaluator.Tests/Unit/MalformedStringTests.cs @@ -0,0 +1,156 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using System.Text; +using Corvus.Text.Json; +using Corvus.Text.Json.Internal; +using Corvus.Text.Json.RuntimeEvaluator; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Text.Json.RuntimeEvaluator.Tests.Unit; + +/// +/// A string that is not well-formed text (an escape of half of a surrogate pair, or bytes that are not UTF-8) is +/// accepted when the document is parsed, and is checked when a keyword reads it: a keyword that reads its characters +/// reports it not valid, a keyword that compares it finds it equal to no well-formed text, and nothing throws +/// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). +/// +[TestClass] +public class MalformedStringTests +{ + private static readonly string[] ValueSchemas = + [ + """{"pattern": "^.$"}""", + """{"pattern": "^(.)\\1?$"}""", + """{"pattern": "^a"}""", + """{"minLength": 1}""", + """{"maxLength": 5}""", + """{"enum": ["a", "b"]}""", + """{"const": "a"}""", + """{"format": "email"}""", + """{"format": "idn-email"}""", + """{"format": "iri"}""", + """{"format": "date"}""", + """{"format": "uri"}""", + """{"$schema": "http://json-schema.org/draft-07/schema#", "contentMediaType": "application/json"}""", + ]; + + private static readonly string[] NameSchemas = + [ + """{"propertyNames": {"pattern": "^a"}}""", + """{"propertyNames": {"maxLength": 3}}""", + """{"propertyNames": {"format": "idn-hostname"}}""", + """{"patternProperties": {"^a": {}}, "additionalProperties": false}""", + """{"properties": {"a": {}}, "additionalProperties": false}""", + ]; + + // Each is the JSON text of a string, as bytes: some are escapes of half of a surrogate pair, some are bytes that + // are not UTF-8, and some are both. + private static readonly Dictionary Malformed = new() + { + ["lone high surrogate escape"] = Encoding.UTF8.GetBytes("\"\\ud800\""), + ["lone high surrogate escape at the end"] = Encoding.UTF8.GetBytes("\"a\\ud83d\""), + ["lone low surrogate escape"] = Encoding.UTF8.GetBytes("\"\\udc00\""), + ["low surrogate escape after a character"] = Encoding.UTF8.GetBytes("\"a\\udc00\""), + ["high surrogate escape before a character"] = Encoding.UTF8.GetBytes("\"\\ud800x\""), + ["high surrogate escape before another escape"] = Encoding.UTF8.GetBytes("\"\\ud800\\u0061\""), + ["two high surrogate escapes"] = Encoding.UTF8.GetBytes("\"\\ud800\\ud800\""), + ["a surrogate encoded in UTF-8"] = [0x22, 0xED, 0xA0, 0x80, 0x22], + ["a lead byte without its continuation"] = [0x22, 0xC3, 0x28, 0x22], + ["a byte that is never UTF-8"] = [0x22, 0xFF, 0x22], + ["a byte that is never UTF-8 after an escape"] = [0x22, 0x5C, 0x6E, 0xFF, 0x22], + }; + + // Well-formed text that is not all ASCII, escaped or not: every keyword reads it as it always has. + private static readonly (string Name, byte[] Json, string Schema, bool Expected)[] WellFormed = + [ + ("e acute", Encoding.UTF8.GetBytes("\"\u00e9\""), """{"pattern": "^.$"}""", true), + ("e acute", Encoding.UTF8.GetBytes("\"\u00e9\""), """{"minLength": 1, "maxLength": 1}""", true), + ("escaped e acute", Encoding.UTF8.GetBytes("\"\\u00e9\""), """{"pattern": "^.$", "maxLength": 1}""", true), + ("escaped e acute", Encoding.UTF8.GetBytes("\"\\u00e9\""), """{"const": "\u00e9"}""", true), + ("surrogate pair escape", Encoding.UTF8.GetBytes("\"\\ud83d\\ude00\""), """{"pattern": "^.$", "minLength": 1, "maxLength": 1}""", true), + ("surrogate pair escape", Encoding.UTF8.GetBytes("\"\\ud83d\\ude00\""), """{"enum": ["\ud83d\ude00"]}""", true), + ("emoji", Encoding.UTF8.GetBytes("\"\ud83d\ude00x\""), """{"pattern": "^.x$", "maxLength": 2}""", true), + ("emoji", Encoding.UTF8.GetBytes("\"\ud83d\ude00x\""), """{"maxLength": 1}""", false), + ("unicode email", Encoding.UTF8.GetBytes("\"\u00e9@example.com\""), """{"format": "idn-email"}""", true), + ]; + + public static IEnumerable Cases() + { + foreach (bool builder in new[] { false, true }) + { + foreach (JsonSchemaCodeGeneration generation in new[] { JsonSchemaCodeGeneration.Disabled, JsonSchemaCodeGeneration.Eager }) + { + foreach (string name in Malformed.Keys) + { + foreach (string schema in ValueSchemas) + { + yield return [name, schema, false, generation, builder]; + } + + foreach (string schema in NameSchemas) + { + yield return ["key " + name, schema, false, generation, builder]; + } + + // A keyword that does not read the characters. + yield return [name, """{"type": "string"}""", true, generation, builder]; + yield return ["key " + name, """{"properties": {"a": {}}}""", true, generation, builder]; + yield return ["key " + name, """{"minProperties": 1}""", true, generation, builder]; + } + + foreach ((string name, _, string schema, bool expected) in WellFormed) + { + yield return ["well-formed " + name, schema, expected, generation, builder]; + } + } + } + } + + [TestMethod] + [DynamicData(nameof(Cases))] + public void AKeywordThatReadsAMalformedStringReportsItNotValid(string name, string schema, bool expected, JsonSchemaCodeGeneration generation, bool builder) + { + byte[] instance = name.StartsWith("key ", StringComparison.Ordinal) + ? [.. "{"u8.ToArray(), .. Malformed[name.Substring(4)], .. ": 1}"u8.ToArray()] + : name.StartsWith("well-formed ", StringComparison.Ordinal) + ? WellFormed.First(w => w.Name == name.Substring(12)).Json + : Malformed[name]; + + var options = new JsonSchemaEvaluatorOptions { AssertFormat = true, CodeGeneration = generation }; + using JsonSchemaEvaluator evaluator = JsonSchemaEvaluator.Compile(schema, options); + using ParsedJsonDocument doc = ParsedJsonDocument.Parse(instance); + + if (builder) + { + // A document that is not parsed text is read through its interface. + using JsonWorkspace workspace = JsonWorkspace.Create(); + using JsonDocumentBuilder built = doc.RootElement.CreateBuilder(workspace); + AssertEvaluates(evaluator, built.RootElement, expected); + } + else + { + AssertEvaluates(evaluator, doc.RootElement, expected); + } + } + + [TestMethod] + public void TwoDifferentLoneSurrogateEscapesAreDifferentItems() + { + using JsonSchemaEvaluator evaluator = JsonSchemaEvaluator.Compile("""{"uniqueItems": true}"""); + Assert.IsTrue(evaluator.Evaluate("""["\ud800", "\udc00", "\ud800x"]""")); + Assert.IsFalse(evaluator.Evaluate("""["\ud800", "\ud800"]""")); + + // An escape and the bytes it is read as are one item. + Assert.IsFalse(evaluator.Evaluate(new ReadOnlyMemory([.. "[\"\\ud800\", \""u8.ToArray(), 0xED, 0xA0, 0x80, .. "\"]"u8.ToArray()]))); + } + + private static void AssertEvaluates(JsonSchemaEvaluator evaluator, in T instance, bool expected) + where T : struct, IJsonElement + { + Assert.AreEqual(expected, evaluator.Evaluate(instance), "flag mode"); + using JsonSchemaResultsCollector collector = JsonSchemaResultsCollector.Create(JsonSchemaResultsLevel.Verbose); + Assert.AreEqual(expected, evaluator.Evaluate(instance, collector), "with a results collector"); + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.RuntimeEvaluator.Tests/Unit/PatternMatcherTests.cs b/tests/Corvus.Text.Json.RuntimeEvaluator.Tests/Unit/PatternMatcherTests.cs index 35b4863c189..bc45067e715 100644 --- a/tests/Corvus.Text.Json.RuntimeEvaluator.Tests/Unit/PatternMatcherTests.cs +++ b/tests/Corvus.Text.Json.RuntimeEvaluator.Tests/Unit/PatternMatcherTests.cs @@ -322,7 +322,7 @@ public void MatchersAgreeWithTheRegularExpression() foreach (string input in Inputs) { bool expected = regex.IsMatch(input); - bool actual = matcher.IsMatch(Encoding.UTF8.GetBytes(input)); + bool actual = matcher.IsMatch(Encoding.UTF8.GetBytes(input), knownUtf8: false); Assert.AreEqual(expected, actual, $"pattern {pattern} translated {regex} input \"{input}\" bytes {BitConverter.ToString(Encoding.UTF8.GetBytes(input))}"); checkedCount++; } @@ -341,8 +341,8 @@ public void ACaseInsensitiveBackreferenceToAnyLetterAnswersAsEcma262Says() var options = new JsonSchemaEvaluatorOptions { RegexEdition = Corvus.Ecma262.RegularExpressions.RegexEdition.Current }; PatternMatcher wide = PatternMatcher.Create(@"^(?i:(.+)-\1)$", options); Assert.IsTrue(wide.UsesRegex); - Assert.IsTrue(wide.IsMatch(Encoding.UTF8.GetBytes("\u03C3\u03C2-\u03A3\u03C3"))); - Assert.IsFalse(wide.IsMatch(Encoding.UTF8.GetBytes("\u03C3\u03C2-\u03A3\u03B1"))); + Assert.IsTrue(wide.IsMatch(Encoding.UTF8.GetBytes("\u03C3\u03C2-\u03A3\u03C3"), knownUtf8: false)); + Assert.IsFalse(wide.IsMatch(Encoding.UTF8.GetBytes("\u03C3\u03C2-\u03A3\u03B1"), knownUtf8: false)); } /// @@ -360,8 +360,8 @@ public void ARegexFromTheRegexProviderIsUsedAsItWas() PatternMatcher matcher = PatternMatcher.Create("^(?:a|b)+$", options); Assert.IsNull(matcher.EcmaExpression); - Assert.IsTrue(matcher.IsMatch("provided"u8)); - Assert.IsFalse(matcher.IsMatch("ab"u8)); + Assert.IsTrue(matcher.IsMatch("provided"u8, knownUtf8: false)); + Assert.IsFalse(matcher.IsMatch("ab"u8, knownUtf8: false)); } /// @@ -387,7 +387,7 @@ public void ARegexFromTheEcmaRegexProviderIsUsedWhenItIsWhatTheEvaluatorWouldCom PatternMatcher compiled = PatternMatcher.Create("^(?:a|b)+$", options, JsonSchemaDialect.Draft202012); Assert.AreNotSame(given, compiled.EcmaExpression); Assert.AreEqual(Corvus.Ecma262.RegularExpressions.RegexEdition.Es2020, compiled.EcmaExpression!.Edition); - Assert.IsTrue(compiled.IsMatch("abba"u8)); + Assert.IsTrue(compiled.IsMatch("abba"u8, knownUtf8: false)); } /// @@ -412,11 +412,11 @@ public void TheModifierGroupOfTodaysGrammarIsRefusedUnderTheDraftsThatCiteECMASc } else { - Assert.IsTrue(PatternMatcher.Create("^(?i:ab)c$", options, dialect).IsMatch("ABc"u8)); + Assert.IsTrue(PatternMatcher.Create("^(?i:ab)c$", options, dialect).IsMatch("ABc"u8, knownUtf8: false)); } var current = new JsonSchemaEvaluatorOptions { RegexEdition = Corvus.Ecma262.RegularExpressions.RegexEdition.Current }; - Assert.IsTrue(PatternMatcher.Create("^(?i:ab)c$", current, dialect).IsMatch("ABc"u8)); + Assert.IsTrue(PatternMatcher.Create("^(?i:ab)c$", current, dialect).IsMatch("ABc"u8, knownUtf8: false)); } /// @@ -430,7 +430,7 @@ public void AMatchPastItsTimeoutThrowsTheTimeoutExceptionOfDotNet() PatternMatcher matcher = PatternMatcher.Create(@"^(?:(a)|b)*\1c$", options); Assert.IsNotNull(matcher.EcmaExpression); byte[] text = Encoding.UTF8.GetBytes(new string('a', 1_000_000)); - System.Text.RegularExpressions.RegexMatchTimeoutException thrown = Assert.ThrowsExactly(() => matcher.IsMatch(text)); + System.Text.RegularExpressions.RegexMatchTimeoutException thrown = Assert.ThrowsExactly(() => matcher.IsMatch(text, knownUtf8: false)); Assert.AreEqual(@"^(?:(a)|b)*\1c$", thrown.Pattern); } @@ -684,7 +684,7 @@ private static void AssertCases((string Pattern, string[] Matches, string[] Fail { foreach (string text in texts) { - if (matcher.IsMatch(Encoding.UTF8.GetBytes(text)) != expected) + if (matcher.IsMatch(Encoding.UTF8.GetBytes(text), knownUtf8: false) != expected) { wrong.Add($"matcher: {pattern} on \"{text}\", want {expected}"); } diff --git a/tests/Corvus.Text.Json.SourceGenerator.Tests/Corvus.Text.Json.SourceGenerator.Tests.csproj b/tests/Corvus.Text.Json.SourceGenerator.Tests/Corvus.Text.Json.SourceGenerator.Tests.csproj index c86e5e1c411..3b2dda4290b 100644 --- a/tests/Corvus.Text.Json.SourceGenerator.Tests/Corvus.Text.Json.SourceGenerator.Tests.csproj +++ b/tests/Corvus.Text.Json.SourceGenerator.Tests/Corvus.Text.Json.SourceGenerator.Tests.csproj @@ -20,6 +20,9 @@ + + @@ -31,10 +34,12 @@ assemblies to every project that references it (GetDependencyTargetPaths), so that analyzer hosts can load them next to the generator. This project runs on net10.0, where the framework's version 10 assemblies are the ones that load, so the generator's copies are dropped before reference resolution. Keeping them made - ResolveAssemblyReference see two primary references of different versions to each (MSB3243). --> + ResolveAssemblyReference see two primary references of different versions to each (MSB3243). The V4 generator + hands over its private Microsoft.Bcl.Memory the same way, which the V4 tools' package reference also brings at + the central version, so the generator's copy is dropped too. --> - <_ResolvedProjectReferencePaths Remove="@(_ResolvedProjectReferencePaths)" Condition="'%(Filename)' == 'System.Text.Json' or '%(Filename)' == 'System.Text.Encodings.Web'" /> + <_ResolvedProjectReferencePaths Remove="@(_ResolvedProjectReferencePaths)" Condition="'%(Filename)' == 'System.Text.Json' or '%(Filename)' == 'System.Text.Encodings.Web' or '%(Filename)' == 'Microsoft.Bcl.Memory'" /> diff --git a/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexEngineOptions.cs b/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexEngineOptions.cs index e3321944546..84a5a24204e 100644 --- a/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexEngineOptions.cs +++ b/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexEngineOptions.cs @@ -17,15 +17,20 @@ internal static class RegexEngineOptions { /// Gets the options of a build that sets CorvusTextJsonRegexEngine. /// The engine: Ecma262 or DotNet. + /// The value of CorvusTextJsonRegexMatchTimeout, or to leave it unset. /// The options. - public static AnalyzerConfigOptionsProvider For(string engine) => - new GlobalOptionsProvider(ImmutableDictionary.Empty.Add("build_property.CorvusTextJsonRegexEngine", engine)); + public static AnalyzerConfigOptionsProvider For(string engine, string? matchTimeout = null) => + new GlobalOptionsProvider(With(ImmutableDictionary.Empty.Add("build_property.CorvusTextJsonRegexEngine", engine), "build_property.CorvusTextJsonRegexMatchTimeout", matchTimeout)); /// Gets the options of a build that sets the V4 source generator's CorvusJsonSchemaRegexEngine. /// The engine: Ecma262 or DotNet. + /// The value of CorvusJsonSchemaRegexMatchTimeout, or to leave it unset. /// The options. - public static AnalyzerConfigOptionsProvider ForV4(string engine) => - new GlobalOptionsProvider(ImmutableDictionary.Empty.Add("build_property.CorvusJsonSchemaRegexEngine", engine)); + public static AnalyzerConfigOptionsProvider ForV4(string engine, string? matchTimeout = null) => + new GlobalOptionsProvider(With(ImmutableDictionary.Empty.Add("build_property.CorvusJsonSchemaRegexEngine", engine), "build_property.CorvusJsonSchemaRegexMatchTimeout", matchTimeout)); + + private static ImmutableDictionary With(ImmutableDictionary values, string key, string? value) => + value is null ? values : values.Add(key, value); private sealed class GlobalOptionsProvider(ImmutableDictionary values) : AnalyzerConfigOptionsProvider { diff --git a/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexMatchTimeoutTests.cs b/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexMatchTimeoutTests.cs index 96c89786eff..db799231b24 100644 --- a/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexMatchTimeoutTests.cs +++ b/tests/Corvus.Text.Json.SourceGenerator.Tests/RegexMatchTimeoutTests.cs @@ -9,9 +9,10 @@ namespace Corvus.Text.Json.SourceGenerator.Tests; /// -/// The code the source generator emits has the regular expression match timeout of 1 second. Roslyn does not chain -/// generators, so there is no [GeneratedRegex] in it: a generated type constructs its expression, and the -/// program's options give the evaluator the timeout for the expressions it constructs. +/// The code the source generator emits has the regular expression match timeout of 1 second, or the one +/// CorvusTextJsonRegexMatchTimeout sets (-1 for none). Roslyn does not chain generators, so there is no +/// [GeneratedRegex] in it: a generated type constructs its expression, and the program's options give the +/// evaluator the timeout for the expressions it constructs. /// [TestClass] public class RegexMatchTimeoutTests @@ -43,27 +44,14 @@ namespace RegexTimeoutTests; private static readonly string TestDirectory = Path.Combine(Path.GetTempPath(), "corvus-regex-timeout-tests"); [TestMethod] - public void EmittedCode_ConstructsItsRegularExpressionsWithTheTimeout() + [DataRow(null, "global::System.TimeSpan.FromMilliseconds(1000)")] + [DataRow("", "global::System.TimeSpan.FromMilliseconds(1000)")] + [DataRow("250", "global::System.TimeSpan.FromMilliseconds(250)")] + [DataRow("-1", "global::System.Text.RegularExpressions.Regex.InfiniteMatchTimeout")] + public void EmittedCode_ConstructsItsRegularExpressionsWithTheTimeout(string? matchTimeout, string expectedTimeout) { - IEnumerable references = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) - .Split(Path.PathSeparator) - .Where(p => Path.GetFileName(p) is "System.Runtime.dll" or "System.Private.CoreLib.dll" or "netstandard.dll" or "mscorlib.dll") - .Select(p => MetadataReference.CreateFromFile(p)); - - CSharpCompilation compilation = CSharpCompilation.Create( - "RegexTimeoutTests", - [CSharpSyntaxTree.ParseText(Source, path: Path.Combine(TestDirectory, "Root.cs"))], - references, - new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); - // The translation to .NET's regular expressions, as the DotNet engine writes it. - GeneratorDriver driver = CSharpGeneratorDriver.Create( - [new IncrementalSourceGenerator().AsSourceGenerator()], - additionalTexts: [new InMemoryAdditionalText(Path.Combine(TestDirectory, SchemaFileName), Schema)], - optionsProvider: RegexEngineOptions.For("DotNet")); - - driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out ImmutableArray _); - GeneratorRunResult result = driver.GetRunResult().Results[0]; + GeneratorRunResult result = Run(matchTimeout); Assert.IsNull(result.Exception, $"The generator threw: {result.Exception}"); string[] lines = @@ -77,8 +65,8 @@ .. result.GeneratedSources string[] expected = [ - """RegexMatchTimeout = global::System.TimeSpan.FromMilliseconds(1000),""", - """private static Regex CreatePatternProperties() => new("^(?:a|aa)+-\\z", RegexOptions.Compiled, global::System.TimeSpan.FromMilliseconds(1000));""", + $"RegexMatchTimeout = {expectedTimeout},", + $"private static Regex CreatePatternProperties() => new(\"^(?:a|aa)+-\\\\z\", RegexOptions.Compiled, {expectedTimeout});", ]; if (!expected.SequenceEqual(lines, StringComparer.Ordinal)) @@ -87,6 +75,40 @@ .. result.GeneratedSources } } + [TestMethod] + [DataRow("0")] + [DataRow("-2")] + [DataRow("1s")] + public void ATimeoutThatIsNotAPositiveNumberOfMillisecondsOrMinusOne_IsRefused(string matchTimeout) + { + GeneratorRunResult result = Run(matchTimeout); + + Assert.IsNotNull(result.Exception); + StringAssert.Contains(result.Exception.Message, "CorvusTextJsonRegexMatchTimeout"); + } + + private static GeneratorRunResult Run(string? matchTimeout) + { + IEnumerable references = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) + .Split(Path.PathSeparator) + .Where(p => Path.GetFileName(p) is "System.Runtime.dll" or "System.Private.CoreLib.dll" or "netstandard.dll" or "mscorlib.dll") + .Select(p => MetadataReference.CreateFromFile(p)); + + CSharpCompilation compilation = CSharpCompilation.Create( + "RegexTimeoutTests", + [CSharpSyntaxTree.ParseText(Source, path: Path.Combine(TestDirectory, "Root.cs"))], + references, + new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + + GeneratorDriver driver = CSharpGeneratorDriver.Create( + [new IncrementalSourceGenerator().AsSourceGenerator()], + additionalTexts: [new InMemoryAdditionalText(Path.Combine(TestDirectory, SchemaFileName), Schema)], + optionsProvider: RegexEngineOptions.For("DotNet", matchTimeout)); + + driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out ImmutableArray _); + return driver.GetRunResult().Results[0]; + } + private sealed class InMemoryAdditionalText(string path, string text) : AdditionalText { private readonly SourceText sourceText = SourceText.From(text, Encoding.UTF8); diff --git a/tests/Corvus.Text.Json.SourceGenerator.Tests/V4SourceGeneratorRegexPatternTests.cs b/tests/Corvus.Text.Json.SourceGenerator.Tests/V4SourceGeneratorRegexPatternTests.cs index 445209bcd69..b1bfa3fe127 100644 --- a/tests/Corvus.Text.Json.SourceGenerator.Tests/V4SourceGeneratorRegexPatternTests.cs +++ b/tests/Corvus.Text.Json.SourceGenerator.Tests/V4SourceGeneratorRegexPatternTests.cs @@ -158,7 +158,35 @@ public void ByDefault_TheCodeCarriesTheLibrarysMatchers() Assert.IsFalse(code.Contains("Regex CreatePattern", StringComparison.Ordinal)); } - private static GeneratorRunResult Run(string schema, string? engine = null) + [TestMethod] + [DataRow("250", "global::System.TimeSpan.FromMilliseconds(250)")] + [DataRow("-1", "global::System.Text.RegularExpressions.Regex.InfiniteMatchTimeout")] + public void EmittedCode_TakesTheTimeoutTheBuildSets(string matchTimeout, string expectedTimeout) + { + // CorvusJsonSchemaRegexMatchTimeout sets the timeout of the expressions generated code constructs, or none (-1). + GeneratorRunResult result = Run(""" + { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { "code": { "type": "string", "pattern": "^(a|aa)+$" } } + } + """, + "DotNet", + matchTimeout); + + Assert.IsNull(result.Exception, $"The generator threw: {result.Exception}"); + string[] lines = + [ + .. result.GeneratedSources + .SelectMany(s => s.SourceText.ToString().Split('\n')) + .Select(l => l.Trim()) + .Where(l => l.Contains("Regex Create", StringComparison.Ordinal) && l.Contains("=> new(", StringComparison.Ordinal)) + ]; + + CollectionAssert.AreEqual(new[] { $"private static Regex CreatePattern() => new(\"^(?:a|aa)+\\\\z\", RegexOptions.Compiled, {expectedTimeout});" }, lines, string.Join("\n", lines)); + } + + private static GeneratorRunResult Run(string schema, string? engine = null, string? matchTimeout = null) { IEnumerable references = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) .Split(Path.PathSeparator) @@ -174,7 +202,7 @@ private static GeneratorRunResult Run(string schema, string? engine = null) GeneratorDriver driver = CSharpGeneratorDriver.Create( [new V4SourceGenerator::Corvus.Json.SourceGenerator.IncrementalSourceGenerator().AsSourceGenerator()], additionalTexts: [new InMemoryAdditionalText(Path.Combine(TestDirectory, SchemaFileName), schema)], - optionsProvider: engine is null ? null : RegexEngineOptions.ForV4(engine)); + optionsProvider: engine is null ? null : RegexEngineOptions.ForV4(engine, matchTimeout)); driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out ImmutableArray _); return driver.GetRunResult().Results[0]; diff --git a/tests/Corvus.Text.Json.SourceGenerator.Tests/V4SourceGeneratorToolsHintNameTests.cs b/tests/Corvus.Text.Json.SourceGenerator.Tests/V4SourceGeneratorToolsHintNameTests.cs new file mode 100644 index 00000000000..76bd1a16585 --- /dev/null +++ b/tests/Corvus.Text.Json.SourceGenerator.Tests/V4SourceGeneratorToolsHintNameTests.cs @@ -0,0 +1,85 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +extern alias V4Tools; + +using System.Collections.Immutable; +using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tools = V4Tools::Corvus.Json.SourceGeneratorTools.SourceGeneratorHelpers; + +namespace Corvus.Text.Json.SourceGenerator.Tests; + +/// +/// A generator that calls SourceGeneratorHelpers.GenerateCode() (Corvus.Json.SourceGeneratorTools) more than +/// once can generate types of the same name in different namespaces without a clash of hint names +/// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/651). +/// +[TestClass] +public class V4SourceGeneratorToolsHintNameTests +{ + private static readonly string SchemaPath = Path.Combine(Path.GetTempPath(), "corvus-v4-tools-hint-names", "foo.json"); + + [TestMethod] + public void TypesOfTheSameNameInDifferentNamespaces_HaveDistinctHintNames() + { + IEnumerable references = ((string)AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")!) + .Split(Path.PathSeparator) + .Where(p => Path.GetFileName(p) is "System.Runtime.dll" or "System.Private.CoreLib.dll" or "netstandard.dll" or "mscorlib.dll") + .Select(p => MetadataReference.CreateFromFile(p)); + + CSharpCompilation compilation = CSharpCompilation.Create("HintNameTests", [], references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + + GeneratorDriver driver = CSharpGeneratorDriver.Create( + [new TwoGenerationsGenerator().AsSourceGenerator()], + additionalTexts: [new InMemoryAdditionalText(SchemaPath, """{ "type": "object", "properties": { "name": { "type": "string" } } }""")]); + + driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out ImmutableArray _); + GeneratorRunResult result = driver.GetRunResult().Results[0]; + + Assert.IsNull(result.Exception, $"The generator threw: {result.Exception}"); + string[] fooHints = [.. result.GeneratedSources.Select(s => s.HintName).Where(h => h.StartsWith("Foo.", StringComparison.Ordinal))]; + Assert.IsTrue(fooHints.Length >= 2, string.Join(", ", result.GeneratedSources.Select(s => s.HintName))); + string[] hashes = [.. fooHints.Select(h => System.Text.RegularExpressions.Regex.Match(h, @"\.([0-9a-f]{8})\.g\.cs$")).Select(m => m.Success ? m.Groups[1].Value : "none").Distinct()]; + CollectionAssert.DoesNotContain(hashes, "none", string.Join(", ", fooHints)); + Assert.AreEqual(2, hashes.Length, string.Join(", ", fooHints)); + Assert.IsTrue(result.GeneratedSources.Any(s => s.SourceText.ToString().Contains("namespace First", StringComparison.Ordinal))); + Assert.IsTrue(result.GeneratedSources.Any(s => s.SourceText.ToString().Contains("namespace Second", StringComparison.Ordinal))); + } + + /// + /// Generates the same schema as the type Foo in two namespaces, with a call to GenerateCode() for each. + /// + private sealed class TwoGenerationsGenerator : IIncrementalGenerator + { + private static readonly V4Tools::Corvus.Json.CodeGeneration.VocabularyRegistry VocabularyRegistry = Tools.CreateVocabularyRegistry(Tools.CreateMetaSchemaResolver()); + + public void Initialize(IncrementalGeneratorInitializationContext context) + { + context.RegisterSourceOutput(context.AdditionalTextsProvider.Collect(), static (production, texts) => + { + Tools.GenerationContext generationContext = new( + Tools.BuildDocumentResolver(texts, production.CancellationToken), + new Tools.GlobalOptions(V4Tools::Corvus.Json.CodeGeneration.Draft202012.VocabularyAnalyser.DefaultVocabulary, false, true, false, [])); + + foreach (string ns in new[] { "First", "Second" }) + { + Tools.GenerateCode(production, new Tools.TypesToGenerate([new Tools.GenerationSpecification(ns, SchemaPath, false, "Foo")], generationContext), VocabularyRegistry); + } + }); + } + } + + private sealed class InMemoryAdditionalText(string path, string text) : AdditionalText + { + private readonly SourceText sourceText = SourceText.From(text, Encoding.UTF8); + + public override string Path => path; + + public override SourceText? GetText(CancellationToken cancellationToken = default) => this.sourceText; + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests.GeneratedModels/ApplyDefaultsModel.cs b/tests/Corvus.Text.Json.Tests.GeneratedModels/ApplyDefaultsModel.cs new file mode 100644 index 00000000000..662dcc68ef8 --- /dev/null +++ b/tests/Corvus.Text.Json.Tests.GeneratedModels/ApplyDefaultsModel.cs @@ -0,0 +1,6 @@ +namespace Corvus.Text.Json.Tests.GeneratedModels.Draft202012; + +[JsonSchemaTypeGenerator("./apply-defaults-2020-12.json")] +public readonly partial struct ApplyDefaultsModel +{ +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests.GeneratedModels/Corvus.Text.Json.Tests.GeneratedModels.csproj b/tests/Corvus.Text.Json.Tests.GeneratedModels/Corvus.Text.Json.Tests.GeneratedModels.csproj index 922d8253f40..38b02b978e7 100644 --- a/tests/Corvus.Text.Json.Tests.GeneratedModels/Corvus.Text.Json.Tests.GeneratedModels.csproj +++ b/tests/Corvus.Text.Json.Tests.GeneratedModels/Corvus.Text.Json.Tests.GeneratedModels.csproj @@ -20,6 +20,8 @@ + + diff --git a/tests/Corvus.Text.Json.Tests.GeneratedModels/MalformedTextModel.cs b/tests/Corvus.Text.Json.Tests.GeneratedModels/MalformedTextModel.cs new file mode 100644 index 00000000000..5a1f76f4b89 --- /dev/null +++ b/tests/Corvus.Text.Json.Tests.GeneratedModels/MalformedTextModel.cs @@ -0,0 +1,6 @@ +namespace Corvus.Text.Json.Tests.GeneratedModels.Draft202012; + +[JsonSchemaTypeGenerator("./malformed-text-2020-12.json")] +public readonly partial struct MalformedTextModel +{ +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests.GeneratedModels/apply-defaults-2020-12.json b/tests/Corvus.Text.Json.Tests.GeneratedModels/apply-defaults-2020-12.json new file mode 100644 index 00000000000..242df0e6cd7 --- /dev/null +++ b/tests/Corvus.Text.Json.Tests.GeneratedModels/apply-defaults-2020-12.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "required": ["name"], + "properties": { + "name": { "type": "string" }, + "retries": { "type": "integer", "format": "int32", "default": 3 }, + "settings": { + "type": "object", + "default": {}, + "properties": { + "port": { "type": "integer", "format": "int32", "default": 502 }, + "host": { "type": "string", "default": "localhost" } + } + }, + "limits": { + "type": "object", + "properties": { + "max": { "type": "integer", "format": "int32", "default": 10 } + } + } + } +} diff --git a/tests/Corvus.Text.Json.Tests.GeneratedModels/malformed-text-2020-12.json b/tests/Corvus.Text.Json.Tests.GeneratedModels/malformed-text-2020-12.json new file mode 100644 index 00000000000..f58c4acc8a2 --- /dev/null +++ b/tests/Corvus.Text.Json.Tests.GeneratedModels/malformed-text-2020-12.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "code": { "type": "string", "pattern": "^[a-zé]+$", "maxLength": 4 }, + "kind": { "enum": [ "a", "b" ] } + }, + "propertyNames": { "maxLength": 8 } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests/Corvus.Text.Json.Tests.csproj b/tests/Corvus.Text.Json.Tests/Corvus.Text.Json.Tests.csproj index b6fe2fddc2b..8a10ec21251 100644 --- a/tests/Corvus.Text.Json.Tests/Corvus.Text.Json.Tests.csproj +++ b/tests/Corvus.Text.Json.Tests/Corvus.Text.Json.Tests.csproj @@ -92,6 +92,10 @@ + + + + diff --git a/tests/Corvus.Text.Json.Tests/GeneratedApplyDefaultsTests.cs b/tests/Corvus.Text.Json.Tests/GeneratedApplyDefaultsTests.cs new file mode 100644 index 00000000000..60577ca0850 --- /dev/null +++ b/tests/Corvus.Text.Json.Tests/GeneratedApplyDefaultsTests.cs @@ -0,0 +1,85 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using Corvus.Text.Json.Tests.GeneratedModels.Draft202012; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Text.Json.Tests; + +/// +/// The generated ApplyDefaults() writes the schema's defaults into the document +/// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/953). +/// +[TestClass] +public class GeneratedApplyDefaultsTests +{ + [TestMethod] + public void ApplyDefaults_WritesTheDefaultOfEachAbsentProperty() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse("""{"name":"x"}"""); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + + builder.RootElement.ApplyDefaults(); + + Assert.AreEqual("""{"name":"x","count":0,"status":"active"}""", builder.RootElement.ToString()); + } + + [TestMethod] + public void ApplyDefaults_KeepsAPropertyThatIsPresent() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse("""{"name":"x","status":"paused"}"""); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + + builder.RootElement.ApplyDefaults(); + + Assert.AreEqual("""{"name":"x","status":"paused","count":0}""", builder.RootElement.ToString()); + } + + [TestMethod] + public void ApplyDefaults_AppliesTheDefaultsOfNestedObjects() + { + // "settings" is absent and defaults to {}, whose own properties then take their defaults. "limits" is present, + // so its "max" takes its default. Neither the absent nor the present objects lose what they had. + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse("""{"name":"a","limits":{}}"""); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + + builder.RootElement.ApplyDefaults(); + + ApplyDefaultsModel result = builder.RootElement.Clone(); + Assert.AreEqual(3, (int)result.Retries); + Assert.AreEqual(502, (int)result.Settings.Port); + Assert.AreEqual("localhost", (string)result.Settings.Host); + Assert.AreEqual(10, (int)result.Limits.Max); + Assert.IsTrue(result.EvaluateSchema()); + } + + [TestMethod] + public void ApplyDefaults_LeavesAnAbsentObjectWithNoDefaultAbsent() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse("""{"name":"a","settings":{"port":1}}"""); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + + builder.RootElement.ApplyDefaults(); + + Assert.AreEqual("""{"name":"a","settings":{"port":1,"host":"localhost"},"retries":3}""", builder.RootElement.ToString()); + } + + [TestMethod] + public void ApplyDefaults_IsIdempotent() + { + using JsonWorkspace workspace = JsonWorkspace.Create(); + using var source = ParsedJsonDocument.Parse("""{"name":"a"}"""); + using JsonDocumentBuilder builder = source.RootElement.CreateBuilder(workspace); + + builder.RootElement.ApplyDefaults(); + string once = builder.RootElement.ToString(); + builder.RootElement.ApplyDefaults(); + + Assert.AreEqual(once, builder.RootElement.ToString()); + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests/GeneratedArrayCollectionTests.cs b/tests/Corvus.Text.Json.Tests/GeneratedArrayCollectionTests.cs new file mode 100644 index 00000000000..09af7624daa --- /dev/null +++ b/tests/Corvus.Text.Json.Tests/GeneratedArrayCollectionTests.cs @@ -0,0 +1,114 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using System.Collections.Generic; +using System.Linq; +using Corvus.Text.Json.Tests.GeneratedModels.Draft202012; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Text.Json.Tests; + +/// +/// A generated pure array type is a read-only collection of its items +/// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1049). +/// +[TestClass] +public class GeneratedArrayCollectionTests +{ + private const string Json = """[{"id":1,"label":"a"},{"id":2},{"id":3,"label":"c"}]"""; + + [TestMethod] + public void APureArrayType_IsAReadOnlyCollectionOfItsItems() + { + using var doc = ParsedJsonDocument.Parse(Json); + IReadOnlyCollection items = doc.RootElement; + + Assert.AreEqual(3, items.Count); + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, items.Select(i => (int)i.Id).ToArray()); + Assert.AreEqual("c", (string)items.Last().Label); + } + + [TestMethod] + public void Foreach_GivesTheItemsInOrder() + { + using var doc = ParsedJsonDocument.Parse(Json); + var ids = new List(); + foreach (ArrayOfItems.RequiredId item in doc.RootElement) + { + ids.Add((int)item.Id); + } + + CollectionAssert.AreEqual(new[] { 1, 2, 3 }, ids); + } + + [TestMethod] + public void Foreach_AllocatesNothingMoreThanEnumerateArray() + { + using var doc = ParsedJsonDocument.Parse(Json); + ArrayOfItems array = doc.RootElement; + + int OverTheValue() + { + int count = 0; + foreach (ArrayOfItems.RequiredId item in array) + { + count++; + } + + return count; + } + + int OverEnumerateArray() + { + int count = 0; + foreach (ArrayOfItems.RequiredId item in array.EnumerateArray()) + { + count++; + } + + return count; + } + + long overTheValue = LeastAllocated(OverTheValue); + +#if NET + Assert.AreEqual(0, overTheValue); +#else + // On .NET Framework, making each element allocates (EnumerateArray() does the same); foreach over the value + // adds nothing to it. + Assert.AreEqual(LeastAllocated(OverEnumerateArray), overTheValue); +#endif + Assert.AreEqual(3, OverEnumerateArray()); + } + + // The least a hundred calls allocate in any of three windows, after a warm-up. + private static long LeastAllocated(Func run) + { + for (int i = 0; i < 100; i++) + { + Assert.AreEqual(3, run()); + } + + long least = long.MaxValue; + for (int window = 0; window < 3; window++) + { + long before = GC.GetAllocatedBytesForCurrentThread(); + for (int i = 0; i < 100; i++) + { + run(); + } + + least = Math.Min(least, GC.GetAllocatedBytesForCurrentThread() - before); + } + + return least; + } + + [TestMethod] + public void ATupleType_IsNotACollection() + { + Assert.IsFalse(typeof(PureTuple).GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IReadOnlyCollection<>))); + Assert.IsTrue(typeof(ArrayOfItems).GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IReadOnlyCollection<>))); + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests/GeneratedCloneTests.cs b/tests/Corvus.Text.Json.Tests/GeneratedCloneTests.cs new file mode 100644 index 00000000000..bb8ad24c7c1 --- /dev/null +++ b/tests/Corvus.Text.Json.Tests/GeneratedCloneTests.cs @@ -0,0 +1,58 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using Corvus.Text.Json.Internal; +using Corvus.Text.Json.Tests.GeneratedModels.Draft202012; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Text.Json.Tests; + +/// +/// A generated type's Clone() copies only when the instance's document can be disposed: the clone of a clone +/// is the same instance, as does +/// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/927). +/// +[TestClass] +public class GeneratedCloneTests +{ + private const string Json = """{"address":{"street":"1 High Street","city":"Bath"},"notes":"n"}"""; + + [TestMethod] + public void CloningAParsedInstance_CopiesItIntoADocumentThatOutlivesTheOriginal() + { + NestedObject clone; + IJsonDocument original; + using (var doc = ParsedJsonDocument.Parse(Json)) + { + original = ((IJsonElement)doc.RootElement).ParentDocument; + clone = doc.RootElement.Clone(); + } + + Assert.AreNotSame(original, ((IJsonElement)clone).ParentDocument); + Assert.AreEqual("1 High Street", (string)clone.Address.Street); + } + + [TestMethod] + public void CloningAClone_ReturnsTheSameInstance() + { + using var doc = ParsedJsonDocument.Parse(Json); + NestedObject clone = doc.RootElement.Clone(); + NestedObject cloneOfClone = clone.Clone(); + + Assert.AreSame(((IJsonElement)clone).ParentDocument, ((IJsonElement)cloneOfClone).ParentDocument); + Assert.AreEqual(((IJsonElement)clone).ParentDocumentIndex, ((IJsonElement)cloneOfClone).ParentDocumentIndex); + } + + [TestMethod] + public void CloningAValueInsideAClone_ReturnsTheSameInstance() + { + using var doc = ParsedJsonDocument.Parse(Json); + NestedObject clone = doc.RootElement.Clone(); + var address = clone.Address; + var addressClone = address.Clone(); + + Assert.AreSame(((IJsonElement)clone).ParentDocument, ((IJsonElement)addressClone).ParentDocument); + Assert.AreEqual(((IJsonElement)address).ParentDocumentIndex, ((IJsonElement)addressClone).ParentDocumentIndex); + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests/GeneratedMalformedTextTests.cs b/tests/Corvus.Text.Json.Tests/GeneratedMalformedTextTests.cs new file mode 100644 index 00000000000..7c6dbdc7556 --- /dev/null +++ b/tests/Corvus.Text.Json.Tests/GeneratedMalformedTextTests.cs @@ -0,0 +1,78 @@ +// +// Copyright (c) Endjin Limited. All rights reserved. +// + +using System.Text; +using Corvus.Text.Json.Internal; +using Corvus.Text.Json.Tests.GeneratedModels.Draft202012; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Corvus.Text.Json.Tests; + +/// +/// A string that is not well-formed text (an escape of half of a surrogate pair, or bytes that are not UTF-8) is +/// accepted when the document is parsed. A generated type reports it not valid against a keyword that reads its +/// characters, and comparing it with other text gives an answer, never an exception +/// (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1021). +/// +[TestClass] +public class GeneratedMalformedTextTests +{ + [TestMethod] + [DataRow("""{"code": "\ud800"}""")] + [DataRow("""{"code": "ab\udc00"}""")] + [DataRow("""{"kind": "\ud83d"}""")] + [DataRow("""{"\ud800": 1}""")] + [DataRow("""{"a\udc00": 1}""")] + public void AGeneratedTypeReportsAMalformedStringNotValid(string json) + { + using var doc = ParsedJsonDocument.Parse(json); + Assert.IsFalse(doc.RootElement.EvaluateSchema()); + + using JsonSchemaResultsCollector collector = JsonSchemaResultsCollector.Create(JsonSchemaResultsLevel.Verbose); + Assert.IsFalse(doc.RootElement.EvaluateSchema(collector)); + } + + [TestMethod] + public void AGeneratedTypeReportsBytesThatAreNotUtf8NotValid() + { + byte[] json = [.. "{\"code\": \"a"u8.ToArray(), 0xED, 0xA0, 0x80, .. "\"}"u8.ToArray()]; + using var doc = ParsedJsonDocument.Parse(json); + Assert.IsFalse(doc.RootElement.EvaluateSchema()); + } + + [TestMethod] + [DataRow("""{"code": "été", "kind": "a", "é": 1}""")] + [DataRow("""{"code": "été"}""")] + public void AGeneratedTypeReadsWellFormedTextAsItAlwaysHas(string json) + { + using var doc = ParsedJsonDocument.Parse(json); + Assert.IsTrue(doc.RootElement.EvaluateSchema()); + } + + [TestMethod] + public void ValueEquals_AMalformedStringEqualsNoWellFormedText() + { + using var doc = ParsedJsonDocument.Parse("""["a\udc00", "\ud800", "é"]"""); + JsonElement lowAfterA = doc.RootElement[0]; + Assert.IsFalse(lowAfterA.ValueEquals("a")); + Assert.IsFalse(lowAfterA.ValueEquals("a"u8)); + Assert.IsFalse(doc.RootElement[1].ValueEquals("x"u8)); + Assert.IsTrue(doc.RootElement[2].ValueEquals("é")); + } + + [TestMethod] + public void DeepEquals_AMalformedStringEqualsTheSameTextAndNothingElse() + { + using var doc = ParsedJsonDocument.Parse("""[{"k": "\ud800"}, {"k": "\ud800"}, {"k": "\udc00"}, {"\ud800": 1}, {"\ud800": 1}]"""); + JsonElement root = doc.RootElement; + Assert.IsTrue(JsonElementHelpers.DeepEquals(root[0], root[1])); + Assert.IsFalse(JsonElementHelpers.DeepEquals(root[0], root[2])); + Assert.IsTrue(JsonElementHelpers.DeepEquals(root[3], root[4])); + + // The escape and the bytes it is read as are the same text. + byte[] raw = [.. "{\"k\": \""u8.ToArray(), 0xED, 0xA0, 0x80, .. "\"}"u8.ToArray()]; + using var rawDoc = ParsedJsonDocument.Parse(raw); + Assert.IsTrue(JsonElementHelpers.DeepEquals(root[0], rawDoc.RootElement)); + } +} \ No newline at end of file diff --git a/tests/Corvus.Text.Json.Tests/JsonSchemaEvaluationCoverageTests.cs b/tests/Corvus.Text.Json.Tests/JsonSchemaEvaluationCoverageTests.cs index 1526d797312..fb877010b85 100644 --- a/tests/Corvus.Text.Json.Tests/JsonSchemaEvaluationCoverageTests.cs +++ b/tests/Corvus.Text.Json.Tests/JsonSchemaEvaluationCoverageTests.cs @@ -221,10 +221,11 @@ public void MatchEmail_TooLong_ReturnsFalse() } [TestMethod] - public void MatchEmail_LocalPartOver64Chars_ReturnsFalse() + public void MatchEmail_HasNoLimitOnTheLocalPartOrTheWholeAddress() { - // Local part > 64 characters - string localPart = new string('a', 65); + // The other ports limit neither the local part nor the address as a whole, only the domain (253 characters as + // A-labels) (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1029). + string localPart = new string('a', 300); string email = localPart + "@example.com"; var collector = new DummyResultsCollector(); @@ -232,7 +233,7 @@ public void MatchEmail_LocalPartOver64Chars_ReturnsFalse() bool result = JsonSchemaEvaluation.MatchEmail(Encoding.UTF8.GetBytes(email), "dummy"u8, ref context); - Assert.IsFalse(result); + Assert.IsTrue(result); context.Dispose(); } @@ -287,9 +288,11 @@ public void MatchIdnEmail_TooLong_ReturnsFalse() } [TestMethod] - public void MatchIdnEmail_LocalPartOver64Chars_ReturnsFalse() + public void MatchIdnEmail_HasNoLimitOnTheLocalPartOrTheWholeAddress() { - string localPart = new string('a', 65); + // The other ports limit neither the local part nor the address as a whole, only the domain (253 characters as + // A-labels) (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1029). + string localPart = new string('a', 300); string email = localPart + "@example.com"; var collector = new DummyResultsCollector(); @@ -297,7 +300,7 @@ public void MatchIdnEmail_LocalPartOver64Chars_ReturnsFalse() bool result = JsonSchemaEvaluation.MatchIdnEmail(Encoding.UTF8.GetBytes(email), "dummy"u8, ref context); - Assert.IsFalse(result); + Assert.IsTrue(result); context.Dispose(); } diff --git a/tests/Corvus.Text.Json.Tests/JsonSchemaMatchingStringTests.cs b/tests/Corvus.Text.Json.Tests/JsonSchemaMatchingStringTests.cs index 9c0dcd1ce44..6f541422721 100644 --- a/tests/Corvus.Text.Json.Tests/JsonSchemaMatchingStringTests.cs +++ b/tests/Corvus.Text.Json.Tests/JsonSchemaMatchingStringTests.cs @@ -240,12 +240,10 @@ public void MatchIdnHostname_LimitsTheNameAsALabels(string name, bool expected) JsonSchemaContext context = CreateContext(collector, JsonTokenType.String); Assert.AreEqual(expected, JsonSchemaEvaluation.MatchIdnHostname(Encoding.UTF8.GetBytes(value), "dummy"u8, ref context), "idn-hostname"); - // An address whose domain is not a host name is not an address. (An address that is valid by its domain can - // still be over the limit of 320 bytes the idn-email check keeps on the whole address.) - if (!expected) - { - Assert.IsFalse(JsonSchemaEvaluation.MatchIdnEmail(Encoding.UTF8.GetBytes("a@" + value), "dummy"u8, ref context), "idn-email"); - } + // An address is an address exactly when its domain is a host name. The limits are on its parts, not on the + // whole address, so an address of over 320 bytes is valid when its domain is within 253 characters as A-labels + // (https://github.com/corvus-dotnet/Corvus.JsonSchema/issues/1029). + Assert.AreEqual(expected, JsonSchemaEvaluation.MatchIdnEmail(Encoding.UTF8.GetBytes("a@" + value), "dummy"u8, ref context), "idn-email"); collector.AssertState(); context.Dispose();