< Summary

Information
Class: SwiftCollections.Array2DState<T>
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/Array2DState.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 58
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Serialization/State/Array2DState.cs

#LineLine coverage
 1using MemoryPack;
 2using System;
 3using System.Text.Json.Serialization;
 4
 5namespace SwiftCollections;
 6
 7/// <summary>
 8/// Represents the immutable state of a two-dimensional array, including its dimensions and underlying data.
 9/// </summary>
 10/// <remarks>
 11/// This struct is intended for scenarios where a snapshot of a 2D array's state is needed, such as
 12/// serialization or state management. The data is stored in a one-dimensional array in row-major order. The struct is
 13/// serializable and compatible with supported serialization frameworks.
 14/// </remarks>
 15/// <typeparam name="T">The type of elements stored in the array.</typeparam>
 16[Serializable]
 17[MemoryPackable]
 18public readonly partial struct Array2DState<T>
 19{
 20    /// <summary>
 21    /// Gets the width value represented by this field.
 22    /// </summary>
 23    [JsonInclude]
 24    [MemoryPackInclude]
 25    public readonly int Width;
 26
 27    /// <summary>
 28    /// Gets the height value represented by this field.
 29    /// </summary>
 30    [JsonInclude]
 31    [MemoryPackInclude]
 32    public readonly int Height;
 33
 34    /// <summary>
 35    /// Gets the underlying array of data elements contained in the collection.
 36    /// </summary>
 37    [JsonInclude]
 38    [MemoryPackInclude]
 39    public readonly T[] Data;
 40
 41    /// <summary>
 42    /// Initializes a new instance of the Array2DState class with the specified dimensions and data array.
 43    /// </summary>
 44    /// <param name="width">The number of columns in the two-dimensional array. Must be greater than zero.</param>
 45    /// <param name="height">The number of rows in the two-dimensional array. Must be greater than zero.</param>
 46    /// <param name="data">
 47    /// The one-dimensional array containing the elements of the two-dimensional array, stored in row-major order.
 48    /// The length must be equal to width multiplied by height.
 49    /// </param>
 50    [JsonConstructor]
 51    [MemoryPackConstructor]
 52    public Array2DState(int width, int height, T[] data)
 53    {
 1454        Width = width;
 1455        Height = height;
 1456        Data = data;
 1457    }
 58}