ReadOnlyArray2D.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. namespace OpenCvSharp.Internal.Util;
  2. /// <summary>
  3. /// Readonly rectangular array (T[,])
  4. /// </summary>
  5. /// <typeparam name="T"></typeparam>
  6. public class ReadOnlyArray2D<T>
  7. {
  8. private readonly T[,] data;
  9. /// <summary>
  10. /// Constructor
  11. /// </summary>
  12. /// <param name="data"></param>
  13. public ReadOnlyArray2D(T[,] data)
  14. {
  15. this.data = data ?? throw new ArgumentNullException(nameof(data));
  16. }
  17. /// <summary>
  18. /// Indexer
  19. /// </summary>
  20. /// <param name="index0"></param>
  21. /// <param name="index1"></param>
  22. /// <returns></returns>
  23. public ref readonly T this[int index0, int index1] => ref data[index0, index1];
  24. /// <summary>
  25. /// Gets the total number of elements in all the dimensions of the System.Array.
  26. /// </summary>
  27. #pragma warning disable CA1721
  28. public int Length => data.Length;
  29. #pragma warning restore CA1721
  30. /// <summary>
  31. /// Gets a 32-bit integer that represents the number of elements in the specified dimension of the System.Array.
  32. /// </summary>
  33. /// <param name="dimension"></param>
  34. /// <returns></returns>
  35. public int GetLength(int dimension) => data.GetLength(dimension);
  36. /// <summary>
  37. /// Returns internal buffer
  38. /// </summary>
  39. /// <returns></returns>
  40. public T[,] GetBuffer() => data;
  41. }