Show / Hide Table of Contents

Class Common

Defines operations for common data transformation in programs, and some special comparison functions.

Inheritance
object
Common
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TheXDS.MCART.Helpers
Assembly: MCART.dll
Syntax
public static class Common
Remarks

Some of these functions are also implemented as extensions, so to be called they only need to import the namespace TheXDS.MCART and use instance syntax.

Methods

| Edit this page View Source

AllEmpty(params string?[])

Determines if a set of strings are all empty.

Declaration
public static bool AllEmpty(params string?[] stringArray)
Parameters
Type Name Description
string[] stringArray

Strings to check.

Returns
Type Description
bool

true if the strings are empty or null; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if stringArray is null.

| Edit this page View Source

AnyEmpty(out IEnumerable<int>, params string?[])

Determines if any of the strings are empty.

Declaration
public static bool AnyEmpty(out IEnumerable<int> index, params string?[] stringArray)
Parameters
Type Name Description
IEnumerable<int> index

Output argument. Indexes of the empty strings found.

string[] stringArray

Strings to check.

Returns
Type Description
bool

true if any string is empty or null; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if stringArray is null.

| Edit this page View Source

AnyEmpty(out int, params string?[])

Determines if any of the strings are empty.

Declaration
public static bool AnyEmpty(out int firstIndex, params string?[] stringArray)
Parameters
Type Name Description
int firstIndex

Output argument. Index of the first empty string found.

string[] stringArray

Strings to check.

Returns
Type Description
bool

true if any string is empty or null; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if stringArray is null.

| Edit this page View Source

AnyEmpty(params string?[])

Determines if any of the strings are empty.

Declaration
public static bool AnyEmpty(params string?[] stringArray)
Parameters
Type Name Description
string[] stringArray

Strings to check.

Returns
Type Description
bool

true if any string is empty or null; false otherwise.

Exceptions
Type Condition
ArgumentNullException

Thrown if stringArray is null.

| Edit this page View Source

BitCount(in byte)

Gets the bit count of the value.

Declaration
public static byte BitCount(this in byte value)
Parameters
Type Name Description
byte value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

BitCount(in short)

Gets the bit count of the value.

Declaration
public static byte BitCount(this in short value)
Parameters
Type Name Description
short value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

BitCount(in int)

Gets the bit count of the value.

Declaration
public static byte BitCount(this in int value)
Parameters
Type Name Description
int value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

BitCount(in long)

Gets the bit count of the value.

Declaration
public static byte BitCount(this in long value)
Parameters
Type Name Description
long value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

BitCount(in sbyte)

Gets the bit count of the value.

Declaration
[CLSCompliant(false)]
public static byte BitCount(this in sbyte value)
Parameters
Type Name Description
sbyte value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

BitCount(in ushort)

Gets the bit count of the value.

Declaration
[CLSCompliant(false)]
public static byte BitCount(this in ushort value)
Parameters
Type Name Description
ushort value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

BitCount(in uint)

Gets the bit count of the value.

Declaration
[CLSCompliant(false)]
public static byte BitCount(this in uint value)
Parameters
Type Name Description
uint value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

BitCount(in ulong)

Gets the bit count of the value.

Declaration
[CLSCompliant(false)]
public static byte BitCount(this in ulong value)
Parameters
Type Name Description
ulong value

Value to process.

Returns
Type Description
byte

The number of bits set to 1 in the value.

| Edit this page View Source

ByteUnits(in int, IFormatProvider?)

Converts a int value representing a byte count to the easiest-to-read magnitude unit.

Declaration
public static string ByteUnits(this in int bytes, IFormatProvider? format = null)
Parameters
Type Name Description
int bytes

Amount of bytes to represent.

IFormatProvider format

String format to utilize.

Returns
Type Description
string

A string with the byte count using the appropriate magnitude unit.

| Edit this page View Source

ByteUnits(in int, in ByteUnitType, byte, IFormatProvider?)

Converts a int value representing a byte count to the easiest-to-read magnitude unit.

Declaration
public static string ByteUnits(this in int bytes, in Common.ByteUnitType unit, byte magnitude, IFormatProvider? format = null)
Parameters
Type Name Description
int bytes

Amount of bytes to represent.

Common.ByteUnitType unit

Type of units to use.

byte magnitude

Initial magnitude of bytes. 0 indicates that the value of bytes should be treated directly as the value in bytes of the operation. The maximum allowed value is 8 to indicate Yottabytes.

IFormatProvider format

String format to utilize.

Returns
Type Description
string

A string with the byte count using the appropriate magnitude unit.

| Edit this page View Source

ByteUnits(in int, in ByteUnitType, IFormatProvider?)

Converts a int value representing a byte count to the easiest-to-read magnitude unit.

Declaration
public static string ByteUnits(this in int bytes, in Common.ByteUnitType unit, IFormatProvider? format = null)
Parameters
Type Name Description
int bytes

Amount of bytes to represent.

Common.ByteUnitType unit

Type of units to use.

IFormatProvider format

String format to utilize.

Returns
Type Description
string

A string with the byte count using the appropriate magnitude unit.

| Edit this page View Source

ByteUnits(in long, IFormatProvider?)

Converts a long value representing a byte count to the easiest-to-read magnitude unit.

Declaration
public static string ByteUnits(this in long bytes, IFormatProvider? format = null)
Parameters
Type Name Description
long bytes

Amount of bytes to represent.

IFormatProvider format

String format to utilize.

Returns
Type Description
string

A string with the byte count using the appropriate magnitude unit.

| Edit this page View Source

ByteUnits(in long, in ByteUnitType, byte, IFormatProvider?)

Converts a long value representing a byte count to the easiest-to-read magnitude unit.

Declaration
public static string ByteUnits(this in long bytes, in Common.ByteUnitType unit, byte magnitude, IFormatProvider? format = null)
Parameters
Type Name Description
long bytes

Amount of bytes to represent.

Common.ByteUnitType unit

Type of units to use.

byte magnitude

Initial magnitude of bytes. 0 indicates that the value of bytes should be treated directly as the value in bytes of the operation. The maximum allowed value is 8 to indicate Yottabytes.

IFormatProvider format

String format to utilize.

Returns
Type Description
string

A string with the byte count using the appropriate magnitude unit.

| Edit this page View Source

ByteUnits(in long, in ByteUnitType, IFormatProvider?)

Converts a long value representing a byte count to the easiest-to-read magnitude unit.

Declaration
public static string ByteUnits(this in long bytes, in Common.ByteUnitType unit, IFormatProvider? format = null)
Parameters
Type Name Description
long bytes

Amount of bytes to represent.

Common.ByteUnitType unit

Type of units to use.

IFormatProvider format

String format to utilize.

Returns
Type Description
string

A string with the byte count using the appropriate magnitude unit.

| Edit this page View Source

FindConverter(Type)

Searches and retrieves an appropriate TypeConverter to perform the conversion between string and the specified type.

Declaration
public static TypeConverter? FindConverter(Type target)
Parameters
Type Name Description
Type target

Destination type.

Returns
Type Description
TypeConverter

A TypeConverter capable of performing the conversion between string and the specified type, or null if no suitable converter has been found.

Exceptions
Type Condition
ArgumentNullException

Thrown if target is null.

| Edit this page View Source

FindConverter(Type, Type)

Searches and retrieves an appropriate TypeConverter to perform the conversion between the requested types.

Declaration
public static TypeConverter? FindConverter(Type source, Type target)
Parameters
Type Name Description
Type source

Source type.

Type target

Destination type.

Returns
Type Description
TypeConverter

A TypeConverter capable of performing the conversion between the required types, or null if no suitable converter has been found.

Exceptions
Type Condition
ArgumentNullException

Thrown if source or target are null.

| Edit this page View Source

FindConverter<T>()

Searches and retrieves an appropriate TypeConverter to perform the conversion between string and the specified type.

Declaration
public static TypeConverter? FindConverter<T>()
Returns
Type Description
TypeConverter

A TypeConverter capable of performing the conversion between string and the specified type, or null if no suitable converter has been found.

Type Parameters
Name Description
T

Destiation type.

| Edit this page View Source

FindConverter<TSource, TTarget>()

Searches and retrieves an appropriate TypeConverter to perform the conversion between the requested types.

Declaration
public static TypeConverter? FindConverter<TSource, TTarget>()
Returns
Type Description
TypeConverter

A TypeConverter capable of performing the conversion between the required types, or null if no suitable converter has been found.

Type Parameters
Name Description
TSource

Source type.

TTarget

Destination typt.

| Edit this page View Source

FindConverters(Type, Type)

Searches and retrieves an appropriate TypeConverter to perform the conversion between the requested types.

Declaration
public static IEnumerable<TypeConverter> FindConverters(Type source, Type target)
Parameters
Type Name Description
Type source

Source type.

Type target

Destination type.

Returns
Type Description
IEnumerable<TypeConverter>

A TypeConverter capable of performing the conversion between the required types, or null if no suitable converter has been found.

Exceptions
Type Condition
ArgumentNullException

Thrown if source or target are null.

| Edit this page View Source

FlipEndianness(in char)

Inverts the Endianness of a char value.

Declaration
public static char FlipEndianness(this in char value)
Parameters
Type Name Description
char value

Value whose endianness will be inverted.

Returns
Type Description
char

A char whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in double)

Inverts the Endianness of a double value.

Declaration
public static double FlipEndianness(this in double value)
Parameters
Type Name Description
double value

Value whose endianness will be inverted.

Returns
Type Description
double

A double whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in short)

Inverts the Endianness of a short value.

Declaration
public static short FlipEndianness(this in short value)
Parameters
Type Name Description
short value

Value whose endianness will be inverted.

Returns
Type Description
short

A short whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in int)

Inverts the Endianness of a int value.

Declaration
public static int FlipEndianness(this in int value)
Parameters
Type Name Description
int value

Value whose endianness will be inverted.

Returns
Type Description
int

An int whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in long)

Inverts the Endianness of a long value.

Declaration
public static long FlipEndianness(this in long value)
Parameters
Type Name Description
long value

Value whose endianness will be inverted.

Returns
Type Description
long

A long whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in float)

Inverts the Endianness of a float value.

Declaration
public static float FlipEndianness(this in float value)
Parameters
Type Name Description
float value

Value whose endianness will be inverted.

Returns
Type Description
float

A float whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in ushort)

Inverts the Endianness of a ushort value.

Declaration
[CLSCompliant(false)]
public static ushort FlipEndianness(this in ushort value)
Parameters
Type Name Description
ushort value

Value whose endianness will be inverted.

Returns
Type Description
ushort

A ushort whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in uint)

Inverts the Endianness of a uint value.

Declaration
[CLSCompliant(false)]
public static uint FlipEndianness(this in uint value)
Parameters
Type Name Description
uint value

Value whose endianness will be inverted.

Returns
Type Description
uint

A uint whose endianness has been inverted.

| Edit this page View Source

FlipEndianness(in ulong)

Inverts the Endianness of a ulong value.

Declaration
[CLSCompliant(false)]
public static ulong FlipEndianness(this in ulong value)
Parameters
Type Name Description
ulong value

Value whose endianness will be inverted.

Returns
Type Description
ulong

A ulong whose endianness has been inverted.

| Edit this page View Source

IfNotNull<T>(T?, Action<T>)

Executes an operation if a value is not null.

Declaration
public static void IfNotNull<T>(this T? value, Action<T> operation) where T : struct
Parameters
Type Name Description
T? value

Value to check.

Action<T> operation

Operation to execute if value is not null.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IfNotNull<T>(T?, Action<T>)

Executes an operation if a value is not null.

Declaration
public static void IfNotNull<T>(this T? value, Action<T> operation) where T : class
Parameters
Type Name Description
T value

Value to check.

Action<T> operation

Operation to execute if value is not null.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T?, in Range<T>)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T? value, in Range<T> range) where T : struct, IComparable<T>
Parameters
Type Name Description
T? value

Value to check.

Range<T> range

Range of values to check.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T?, in T, in T)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T? value, in T min, in T max) where T : struct, IComparable<T>
Parameters
Type Name Description
T? value

Value to check.

T min

Minimum range value, inclusive.

T max

Maximum range value, inclusive.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T?, in T, in T, in bool)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T? value, in T min, in T max, in bool inclusive) where T : struct, IComparable<T>
Parameters
Type Name Description
T? value

Value to check.

T min

Minimum range value.

T max

Maximum range value.

bool inclusive

If set to true, the minimum and maximum values will be inclusive.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T?, in T, in T, in bool, in bool)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T? value, in T min, in T max, in bool minInclusive, in bool maxInclusive) where T : struct, IComparable<T>
Parameters
Type Name Description
T? value

Value to check.

T min

Minimum range value.

T max

Maximum range value.

bool minInclusive

If set to true, the minimum value will be inclusive in the range.

bool maxInclusive

If set to true, the maximum value will be inclusive in the range.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T, in Range<T>)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T value, in Range<T> range) where T : IComparable<T>
Parameters
Type Name Description
T value

Value to check.

Range<T> range

Range of values to check.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T, in T, in T)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T value, in T min, in T max) where T : IComparable<T>
Parameters
Type Name Description
T value

Value to check.

T min

Minimum range value, inclusive.

T max

Maximum range value, inclusive.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T, in T, in T, in bool)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T value, in T min, in T max, in bool inclusive) where T : IComparable<T>
Parameters
Type Name Description
T value

Value to check.

T min

Minimum range value.

T max

Maximum range value.

bool inclusive

If set to true, the minimum and maximum values will be inclusive.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

IsBetween<T>(T, in T, in T, in bool, in bool)

Checks that the value is within the specified range.

Declaration
public static bool IsBetween<T>(this T value, in T min, in T max, in bool minInclusive, in bool maxInclusive) where T : IComparable<T>
Parameters
Type Name Description
T value

Value to check.

T min

Minimum range value.

T max

Maximum range value.

bool minInclusive

If set to true, the minimum value will be inclusive in the range.

bool maxInclusive

If set to true, the maximum value will be inclusive in the range.

Returns
Type Description
bool

true if the value is inside the specified range, false otherwise.

Type Parameters
Name Description
T

Type of value to check.

| Edit this page View Source

Listed(IEnumerable<string>)

Condenses a list into a string where each element is separated by a new line.

Declaration
public static string Listed(this IEnumerable<string> collection)
Parameters
Type Name Description
IEnumerable<string> collection

Collection of strings to be condensed.

Returns
Type Description
string

A string where each element of the collection is separated by the operating system's line separator string.

Exceptions
Type Condition
ArgumentNullException

Thrown if collection is null.

| Edit this page View Source

Sequence(int, int, int)

Generates a sequence of number in the specified range.

Declaration
public static IEnumerable<int> Sequence(int floor, int top, int stepping)
Parameters
Type Name Description
int floor

Starting value of the sequence.

int top

End value of the sequence.

int stepping

Sequence stepping.

Returns
Type Description
IEnumerable<int>

A sequence of integer numbers starting on the specified floor value and ending on the specified top value.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if stepping is 0.

| Edit this page View Source

Sequence(in int)

Generates a sequence of number in the specified range.

Declaration
public static IEnumerable<int> Sequence(in int top)
Parameters
Type Name Description
int top

End value of the sequence.

Returns
Type Description
IEnumerable<int>

A sequence of integer numbers starting on 0 and ending on the specified top value.

| Edit this page View Source

Sequence(in int, in int)

Generates a sequence of number in the specified range.

Declaration
public static IEnumerable<int> Sequence(in int floor, in int top)
Parameters
Type Name Description
int floor

Starting value of the sequence.

int top

End value of the sequence.

Returns
Type Description
IEnumerable<int>

A sequence of integer numbers starting on the specified floor value and ending on the specified top value.

| Edit this page View Source

ToBits(in byte)

Converts a byte into a collection of bits.

Declaration
public static IEnumerable<bool> ToBits(this in byte value)
Parameters
Type Name Description
byte value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToBits(in short)

Converts a short into a collection of bits.

Declaration
public static IEnumerable<bool> ToBits(this in short value)
Parameters
Type Name Description
short value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToBits(in int)

Converts a int into a collection of bits.

Declaration
public static IEnumerable<bool> ToBits(this in int value)
Parameters
Type Name Description
int value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToBits(in long)

Converts a long into a collection of bits.

Declaration
public static IEnumerable<bool> ToBits(this in long value)
Parameters
Type Name Description
long value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToBits(in sbyte)

Converts a sbyte into a collection of bits.

Declaration
[CLSCompliant(false)]
public static IEnumerable<bool> ToBits(this in sbyte value)
Parameters
Type Name Description
sbyte value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToBits(in ushort)

Converts a ushort into a collection of bits.

Declaration
[CLSCompliant(false)]
public static IEnumerable<bool> ToBits(this in ushort value)
Parameters
Type Name Description
ushort value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToBits(in uint)

Converts a uint into a collection of bits.

Declaration
[CLSCompliant(false)]
public static IEnumerable<bool> ToBits(this in uint value)
Parameters
Type Name Description
uint value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToBits(in ulong)

Converts a ulong into a collection of bits.

Declaration
[CLSCompliant(false)]
public static IEnumerable<bool> ToBits(this in ulong value)
Parameters
Type Name Description
ulong value

Value to be converted.

Returns
Type Description
IEnumerable<bool>

A collection of the bits conforming the value.

| Edit this page View Source

ToHex(in byte)

Converts a byte into its hex representation.

Declaration
public static string ToHex(this in byte @byte)
Parameters
Type Name Description
byte byte

The byte value to convert.

Returns
Type Description
string

the hex representaiton of the byte value.

| Edit this page View Source

ToHex(byte[])

Shortcut of ToString(byte[]) that does not include hyphens.

Declaration
public static string ToHex(this byte[] arr)
Parameters
Type Name Description
byte[] arr

Byte array to convert.

Returns
Type Description
string

The hex representation of the byte array.

Exceptions
Type Condition
ArgumentNullException

Thrown if arr is null.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX