Skip to content

Commit

Permalink
- Updated the template to generate an explicit/override pair of index…
Browse files Browse the repository at this point in the history
…er properties when the array can be enumerated as a single item type

- Regenerated types to use this capability.
  • Loading branch information
mwadams committed Feb 26, 2024
1 parent cdc8c24 commit f0c95a1
Show file tree
Hide file tree
Showing 24 changed files with 1,962 additions and 779 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PersonArray(IEnumerable<JsonAny> value)
}

/// <inheritdoc/>
public JsonAny this[int index]
JsonAny IJsonArray<PersonArray>.this[int index]
{
get
{
Expand All @@ -72,6 +72,38 @@ public JsonAny this[int index]
}
}

/// <summary>
/// Gets the item at the given index.
/// </summary>
/// <param name = "index">The index at which to retrieve the item.</param>
/// <returns>The item at the given index.</returns>
/// <exception cref = "IndexOutOfRangeException">The index was outside the bounds of the array.</exception>
/// <exception cref = "InvalidOperationException">The value is not an array.</exception>
public Corvus.Json.Benchmarking.Models.Person this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new Corvus.Json.Benchmarking.Models.Person(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index].As<Corvus.Json.Benchmarking.Models.Person>();
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}

/// <summary>
/// Conversion from immutable list.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PersonNameElementArray(IEnumerable<JsonAny> value)
}

/// <inheritdoc/>
public JsonAny this[int index]
JsonAny IJsonArray<PersonNameElementArray>.this[int index]
{
get
{
Expand All @@ -72,6 +72,38 @@ public JsonAny this[int index]
}
}

/// <summary>
/// Gets the item at the given index.
/// </summary>
/// <param name = "index">The index at which to retrieve the item.</param>
/// <returns>The item at the given index.</returns>
/// <exception cref = "IndexOutOfRangeException">The index was outside the bounds of the array.</exception>
/// <exception cref = "InvalidOperationException">The value is not an array.</exception>
public Corvus.Json.Benchmarking.Models.PersonNameElement this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new Corvus.Json.Benchmarking.Models.PersonNameElement(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index].As<Corvus.Json.Benchmarking.Models.PersonNameElement>();
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}

/// <summary>
/// Conversion from immutable list.
/// </summary>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public readonly partial struct <#= TypeDeclaration.DotnetTypeName #> : IJsonArra
<# } #>
}

<# if (!CanEnumerateAsSpecificType)
{ #>
/// <inheritdoc/>
public JsonAny this[int index]
{
Expand All @@ -117,6 +119,67 @@ public readonly partial struct <#= TypeDeclaration.DotnetTypeName #> : IJsonArra
throw new InvalidOperationException();
}
}
<# }
else
{ #>
/// <inheritdoc/>
JsonAny IJsonArray<<#= TypeDeclaration.DotnetTypeName #>>.this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new JsonAny(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index];
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}

/// <summary>
/// Gets the item at the given index.
/// </summary>
/// <param name="index">The index at which to retrieve the item.</param>
/// <returns>The item at the given index.</returns>
/// <exception cref="IndexOutOfRangeException">The index was outside the bounds of the array.</exception>
/// <exception cref="InvalidOperationException">The value is not an array.</exception>
public <#= SingleItemsDotnetTypeName #> this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new <#= SingleItemsDotnetTypeName #>(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index].As<<#= SingleItemsDotnetTypeName #>>();
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}
<# } #>

/// <summary>
/// Conversion from immutable list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SchemaArray(IEnumerable<JsonAny> value)
}

/// <inheritdoc/>
public JsonAny this[int index]
JsonAny IJsonArray<SchemaArray>.this[int index]
{
get
{
Expand All @@ -74,6 +74,38 @@ public JsonAny this[int index]
}
}

/// <summary>
/// Gets the item at the given index.
/// </summary>
/// <param name = "index">The index at which to retrieve the item.</param>
/// <returns>The item at the given index.</returns>
/// <exception cref = "IndexOutOfRangeException">The index was outside the bounds of the array.</exception>
/// <exception cref = "InvalidOperationException">The value is not an array.</exception>
public Corvus.Json.JsonSchema.Draft201909.Schema this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new Corvus.Json.JsonSchema.Draft201909.Schema(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index].As<Corvus.Json.JsonSchema.Draft201909.Schema>();
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}

/// <summary>
/// Conversion from immutable list.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public StringArray(IEnumerable<JsonAny> value)
}

/// <inheritdoc/>
public JsonAny this[int index]
JsonAny IJsonArray<StringArray>.this[int index]
{
get
{
Expand All @@ -74,6 +74,38 @@ public JsonAny this[int index]
}
}

/// <summary>
/// Gets the item at the given index.
/// </summary>
/// <param name = "index">The index at which to retrieve the item.</param>
/// <returns>The item at the given index.</returns>
/// <exception cref = "IndexOutOfRangeException">The index was outside the bounds of the array.</exception>
/// <exception cref = "InvalidOperationException">The value is not an array.</exception>
public Corvus.Json.JsonString this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new Corvus.Json.JsonString(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index].As<Corvus.Json.JsonString>();
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}

/// <summary>
/// Conversion from immutable list.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SimpleTypesArray(IEnumerable<JsonAny> value)
}

/// <inheritdoc/>
public JsonAny this[int index]
JsonAny IJsonArray<SimpleTypesArray>.this[int index]
{
get
{
Expand All @@ -76,6 +76,38 @@ public JsonAny this[int index]
}
}

/// <summary>
/// Gets the item at the given index.
/// </summary>
/// <param name = "index">The index at which to retrieve the item.</param>
/// <returns>The item at the given index.</returns>
/// <exception cref = "IndexOutOfRangeException">The index was outside the bounds of the array.</exception>
/// <exception cref = "InvalidOperationException">The value is not an array.</exception>
public Corvus.Json.JsonSchema.Draft201909.Validation.SimpleTypes this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new Corvus.Json.JsonSchema.Draft201909.Validation.SimpleTypes(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index].As<Corvus.Json.JsonSchema.Draft201909.Validation.SimpleTypes>();
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}

/// <summary>
/// Conversion from immutable list.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SchemaArray(IEnumerable<JsonAny> value)
}

/// <inheritdoc/>
public JsonAny this[int index]
JsonAny IJsonArray<SchemaArray>.this[int index]
{
get
{
Expand All @@ -74,6 +74,38 @@ public JsonAny this[int index]
}
}

/// <summary>
/// Gets the item at the given index.
/// </summary>
/// <param name = "index">The index at which to retrieve the item.</param>
/// <returns>The item at the given index.</returns>
/// <exception cref = "IndexOutOfRangeException">The index was outside the bounds of the array.</exception>
/// <exception cref = "InvalidOperationException">The value is not an array.</exception>
public Corvus.Json.JsonSchema.Draft202012.Schema this[int index]
{
get
{
if ((this.backing & Backing.JsonElement) != 0)
{
return new Corvus.Json.JsonSchema.Draft202012.Schema(this.jsonElementBacking[index]);
}

if ((this.backing & Backing.Array) != 0)
{
try
{
return this.arrayBacking[index].As<Corvus.Json.JsonSchema.Draft202012.Schema>();
}
catch (ArgumentOutOfRangeException ex)
{
throw new IndexOutOfRangeException(ex.Message, ex);
}
}

throw new InvalidOperationException();
}
}

/// <summary>
/// Conversion from immutable list.
/// </summary>
Expand Down
Loading

0 comments on commit f0c95a1

Please sign in to comment.