Table of Contents

Class ShortExtensions

Namespace
Ubiety.Dns.Core.Common.Extensions
Assembly
Ubiety.Dns.Core.dll

Provides extension methods for working with ushort values, such as retrieving bytes, setting flag values, and extracting flag information.

public static class ShortExtensions
Inheritance
ShortExtensions
Inherited Members

Methods

GetBytes(ushort)

Retrieves the byte representation of a ushort value.

public static IEnumerable<byte> GetBytes(this ushort value)

Parameters

value ushort

ushort value to convert to a byte array.

Returns

IEnumerable<byte>

IEnumerable<T> where T is byte, representing the bytes of the given value.

GetFlag(ushort, int)

Retrieves the value of a flag at the specified position within a ushort.

public static bool GetFlag(this ushort value, int position)

Parameters

value ushort

ushort from which to extract the flag.

position int

The bit position of the flag to retrieve.

Returns

bool

bool indicating the state of the flag at the specified position.

GetFlag(ushort, int, int)

Retrieves the value of a specified flag from a ushort.

public static ushort GetFlag(this ushort value, int position, int length)

Parameters

value ushort

ushort from which the flag's value will be retrieved.

position int

Bit position within the ushort where the flag resides.

length int

The number of bits representing the flag value.

Returns

ushort

bool indicating the value of the flag at the specified position.

SetFlag(ushort, int, bool)

Sets a flag value at the specified position within a ushort value.

public static ushort SetFlag(this ushort value, int position, bool flagValue)

Parameters

value ushort

ushort to set the flag value on.

position int

The position of the flag to set.

flagValue bool

The value of the flag, where true represents 1 and false represents 0.

Returns

ushort

A ushort with the specified flag value set at the given position.

SetFlag(ushort, int, int, ushort)

Sets a specific flag or flags within a ushort value by updating the bit(s) at a designated position.

public static ushort SetFlag(this ushort value, int position, int length, ushort flagValue)

Parameters

value ushort

ushort to set the flag value on.

position int

The starting bit position where the flag will be set.

length int

The number of bits representing the flag value.

flagValue ushort

The new value to set for the specified flag.

Returns

ushort

ushort with the specified flag value set.