Move to file scoped namespaces.

This commit is contained in:
2022-03-06 13:29:37 +00:00
parent 31750d5978
commit cb79ff60d6
13 changed files with 1461 additions and 1474 deletions

View File

@@ -27,55 +27,54 @@
using System;
using System.Text;
namespace Aaru.Helpers
namespace Aaru.Helpers;
public static partial class ArrayHelpers
{
public static partial class ArrayHelpers
/// <summary>Fills an array with the specified value</summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T value) => ArrayFill(destinationArray, new[]
{
/// <summary>Fills an array with the specified value</summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T value) => ArrayFill(destinationArray, new[]
{
value
});
value
});
/// <summary>Fills an array with the contents of the specified array</summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T[] value)
{
if(destinationArray == null)
throw new ArgumentNullException(nameof(destinationArray));
/// <summary>Fills an array with the contents of the specified array</summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T[] value)
{
if(destinationArray == null)
throw new ArgumentNullException(nameof(destinationArray));
if(value.Length > destinationArray.Length)
throw new ArgumentException("Length of value array must not be more than length of destination");
if(value.Length > destinationArray.Length)
throw new ArgumentException("Length of value array must not be more than length of destination");
// set the initial array value
Array.Copy(value, destinationArray, value.Length);
// set the initial array value
Array.Copy(value, destinationArray, value.Length);
int arrayToFillHalfLength = destinationArray.Length / 2;
int copyLength;
int arrayToFillHalfLength = destinationArray.Length / 2;
int copyLength;
for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1)
Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength);
for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1)
Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength);
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
}
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
}
/// <summary>Converts a byte array to its hexadecimal representation</summary>
/// <param name="array">Byte array</param>
/// <param name="upper"><c>true</c> to use uppercase</param>
/// <returns></returns>
public static string ByteArrayToHex(byte[] array, bool upper = false)
{
var sb = new StringBuilder();
/// <summary>Converts a byte array to its hexadecimal representation</summary>
/// <param name="array">Byte array</param>
/// <param name="upper"><c>true</c> to use uppercase</param>
/// <returns></returns>
public static string ByteArrayToHex(byte[] array, bool upper = false)
{
var sb = new StringBuilder();
for(long i = 0; i < array.LongLength; i++)
sb.AppendFormat("{0:x2}", array[i]);
for(long i = 0; i < array.LongLength; i++)
sb.AppendFormat("{0:x2}", array[i]);
return upper ? sb.ToString().ToUpper() : sb.ToString();
}
return upper ? sb.ToString().ToUpper() : sb.ToString();
}
}