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,10 +27,10 @@
using System; using System;
using System.Text; 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> /// <summary>Fills an array with the specified value</summary>
/// <param name="destinationArray">Array</param> /// <param name="destinationArray">Array</param>
/// <param name="value">Value</param> /// <param name="value">Value</param>
@@ -77,5 +77,4 @@ namespace Aaru.Helpers
return upper ? sb.ToString().ToUpper() : sb.ToString(); return upper ? sb.ToString().ToUpper() : sb.ToString();
} }
}
} }

View File

@@ -32,11 +32,11 @@
using System.Linq; using System.Linq;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Helper operations to work with arrays</summary>
public static partial class ArrayHelpers
{ {
/// <summary>Helper operations to work with arrays</summary>
public static partial class ArrayHelpers
{
/// <summary>Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20)</summary> /// <summary>Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20)</summary>
/// <param name="array">Array</param> /// <param name="array">Array</param>
/// <returns>True if null or whitespace</returns> /// <returns>True if null or whitespace</returns>
@@ -46,5 +46,4 @@ namespace Aaru.Helpers
/// <param name="array">Array</param> /// <param name="array">Array</param>
/// <returns>True if null</returns> /// <returns>True if null</returns>
public static bool ArrayIsNullOrEmpty(byte[] array) => array?.All(b => b == 0x00) != false; public static bool ArrayIsNullOrEmpty(byte[] array) => array?.All(b => b == 0x00) != false;
}
} }

View File

@@ -33,14 +33,14 @@
using System; using System;
using System.Linq; using System.Linq;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>
/// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from
/// the meta data of System.BitConverter. This implementation allows for Endianness consideration.
/// </summary>
public static class BigEndianBitConverter
{ {
/// <summary>
/// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from
/// the meta data of System.BitConverter. This implementation allows for Endianness consideration.
/// </summary>
public static class BigEndianBitConverter
{
/// <summary>Converts the specified double-precision floating point number to a 64-bit signed integer.</summary> /// <summary>Converts the specified double-precision floating point number to a 64-bit signed integer.</summary>
/// <param name="value">The number to convert.</param> /// <param name="value">The number to convert.</param>
/// <returns>A 64-bit signed integer whose value is equivalent to value.</returns> /// <returns>A 64-bit signed integer whose value is equivalent to value.</returns>
@@ -320,5 +320,4 @@ namespace Aaru.Helpers
value[8 + startIndex + 5], value[8 + startIndex + 5],
value[8 + startIndex + 6], value[8 + startIndex + 6],
value[8 + startIndex + 7]); value[8 + startIndex + 7]);
}
} }

View File

@@ -36,16 +36,15 @@
// Copyright © 2011-2022 Natalia Portillo // Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Describes the endianness of bits on a data structure</summary>
public enum BitEndian
{ {
/// <summary>Describes the endianness of bits on a data structure</summary>
public enum BitEndian
{
/// <summary>Little-endian, or least significant bit</summary> /// <summary>Little-endian, or least significant bit</summary>
Little, Little,
/// <summary>Big-endian, or most significant bit</summary> /// <summary>Big-endian, or most significant bit</summary>
Big, Big,
/// <summary>PDP-11 endian, little endian except for 32-bit integers where the 16 halves are swapped between them</summary> /// <summary>PDP-11 endian, little endian except for 32-bit integers where the 16 halves are swapped between them</summary>
Pdp Pdp
}
} }

9
CHS.cs
View File

@@ -30,11 +30,11 @@
// Copyright © 2011-2022 Natalia Portillo // Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Helper operations to work with CHS values</summary>
public static class CHS
{ {
/// <summary>Helper operations to work with CHS values</summary>
public static class CHS
{
/// <summary>Converts a CHS position to a LBA one</summary> /// <summary>Converts a CHS position to a LBA one</summary>
/// <param name="cyl">Cylinder</param> /// <param name="cyl">Cylinder</param>
/// <param name="head">Head</param> /// <param name="head">Head</param>
@@ -45,5 +45,4 @@ namespace Aaru.Helpers
public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) =>
maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1 maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1
: (((cyl * maxHead) + head) * maxSector) + sector - 1; : (((cyl * maxHead) + head) * maxSector) + sector - 1;
}
} }

View File

@@ -30,10 +30,10 @@
// Copyright © 2011-2022 Natalia Portillo // Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
namespace Aaru.Helpers namespace Aaru.Helpers;
public static partial class ArrayHelpers
{ {
public static partial class ArrayHelpers
{
/// <summary>Compares two byte arrays</summary> /// <summary>Compares two byte arrays</summary>
/// <param name="different"><c>true</c> if they are different in any way</param> /// <param name="different"><c>true</c> if they are different in any way</param>
/// <param name="sameSize"><c>true</c> if they have the same size</param> /// <param name="sameSize"><c>true</c> if they have the same size</param>
@@ -68,5 +68,4 @@ namespace Aaru.Helpers
return; return;
} }
} }
}
} }

View File

@@ -30,11 +30,11 @@
// Copyright © 2011-2022 Natalia Portillo // Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Helper operations to count bits</summary>
public static class CountBits
{ {
/// <summary>Helper operations to count bits</summary>
public static class CountBits
{
/// <summary>Counts the number of bits set to <c>true</c> in a number</summary> /// <summary>Counts the number of bits set to <c>true</c> in a number</summary>
/// <param name="number">Number</param> /// <param name="number">Number</param>
/// <returns>Bits set to <c>true</c></returns> /// <returns>Bits set to <c>true</c></returns>
@@ -45,5 +45,4 @@ namespace Aaru.Helpers
return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
} }
}
} }

View File

@@ -34,11 +34,11 @@ using System;
using System.Text; using System.Text;
using Aaru.Console; using Aaru.Console;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Helper operations for timestamp management (date and time)</summary>
public static class DateHandlers
{ {
/// <summary>Helper operations for timestamp management (date and time)</summary>
public static class DateHandlers
{
static readonly DateTime _lisaEpoch = new DateTime(1901, 1, 1, 0, 0, 0); static readonly DateTime _lisaEpoch = new DateTime(1901, 1, 1, 0, 0, 0);
static readonly DateTime _macEpoch = new DateTime(1904, 1, 1, 0, 0, 0); static readonly DateTime _macEpoch = new DateTime(1904, 1, 1, 0, 0, 0);
static readonly DateTime _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); static readonly DateTime _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
@@ -385,5 +385,4 @@ namespace Aaru.Helpers
return new DateTime(1970, 1, 1, 0, 0, 0); return new DateTime(1970, 1, 1, 0, 0, 0);
} }
} }
}
} }

View File

@@ -36,11 +36,11 @@ using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Provides methods to marshal binary data into C# structs</summary>
public static class Marshal
{ {
/// <summary>Provides methods to marshal binary data into C# structs</summary>
public static class Marshal
{
/// <summary>Returns the size of an unmanaged type in bytes.</summary> /// <summary>Returns the size of an unmanaged type in bytes.</summary>
/// <typeparam name="T">The type whose size is to be returned.</typeparam> /// <typeparam name="T">The type whose size is to be returned.</typeparam>
/// <returns>The size, in bytes, of the type that is specified by the <see cref="T" /> generic type parameter.</returns> /// <returns>The size, in bytes, of the type that is specified by the <see cref="T" /> generic type parameter.</returns>
@@ -494,5 +494,4 @@ namespace Aaru.Helpers
return count; return count;
} }
}
} }

View File

@@ -38,13 +38,13 @@
using System; using System;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <inheritdoc />
/// <summary>Defines properties to help marshalling structs from binary data</summary>
[AttributeUsage(AttributeTargets.Struct)]
public sealed class MarshallingPropertiesAttribute : Attribute
{ {
/// <inheritdoc />
/// <summary>Defines properties to help marshalling structs from binary data</summary>
[AttributeUsage(AttributeTargets.Struct)]
public sealed class MarshallingPropertiesAttribute : Attribute
{
/// <inheritdoc /> /// <inheritdoc />
/// <summary>Defines properties to help marshalling structs from binary data</summary> /// <summary>Defines properties to help marshalling structs from binary data</summary>
/// <param name="endian">Defines properties to help marshalling structs from binary data</param> /// <param name="endian">Defines properties to help marshalling structs from binary data</param>
@@ -58,5 +58,4 @@ namespace Aaru.Helpers
public BitEndian Endian { get; } public BitEndian Endian { get; }
/// <summary>Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc).</summary> /// <summary>Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc).</summary>
public bool HasReferences { get; set; } public bool HasReferences { get; set; }
}
} }

View File

@@ -33,11 +33,11 @@
using System.Text; using System.Text;
using Aaru.Console; using Aaru.Console;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Helper operations to get hexadecimal representations of byte arrays</summary>
public static class PrintHex
{ {
/// <summary>Helper operations to get hexadecimal representations of byte arrays</summary>
public static class PrintHex
{
/// <summary>Prints a byte array as hexadecimal values to the console</summary> /// <summary>Prints a byte array as hexadecimal values to the console</summary>
/// <param name="array">Array</param> /// <param name="array">Array</param>
/// <param name="width">Width of line</param> /// <param name="width">Width of line</param>
@@ -132,5 +132,4 @@ namespace Aaru.Helpers
return sb.ToString(); return sb.ToString();
} }
}
} }

View File

@@ -33,11 +33,11 @@
using System; using System;
using System.Text; using System.Text;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Helper operations to work with strings</summary>
public static class StringHandlers
{ {
/// <summary>Helper operations to work with strings</summary>
public static class StringHandlers
{
/// <summary>Converts a null-terminated (aka C string) ASCII byte array to a C# string</summary> /// <summary>Converts a null-terminated (aka C string) ASCII byte array to a C# string</summary>
/// <returns>The corresponding C# string</returns> /// <returns>The corresponding C# string</returns>
/// <param name="cString">A null-terminated (aka C string) ASCII byte array</param> /// <param name="cString">A null-terminated (aka C string) ASCII byte array</param>
@@ -181,5 +181,4 @@ namespace Aaru.Helpers
return temp; return temp;
} }
}
} }

View File

@@ -32,11 +32,11 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace Aaru.Helpers namespace Aaru.Helpers;
/// <summary>Helper operations to work with swapping endians</summary>
public static class Swapping
{ {
/// <summary>Helper operations to work with swapping endians</summary>
public static class Swapping
{
/// <summary>Gets the PDP endian equivalent of the given little endian unsigned integer</summary> /// <summary>Gets the PDP endian equivalent of the given little endian unsigned integer</summary>
/// <param name="x">Little endian unsigned integer</param> /// <param name="x">Little endian unsigned integer</param>
/// <returns>PDP unsigned integer</returns> /// <returns>PDP unsigned integer</returns>
@@ -108,5 +108,4 @@ namespace Aaru.Helpers
return x; return x;
} }
}
} }