Class ValueTypeExtensions
Provides various extension methods for value types and structs.
Inherited Members
Namespace: Swan
Syntax
public static class ValueTypeExtensions
Methods
Clamp(Int32, Int32, Int32)
Clamps the specified value between the minimum and the maximum.
Declaration
public static int Clamp(this int this, int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | this | The value. |
| Int32 | min | The minimum. |
| Int32 | max | The maximum. |
Returns
| Type | Description |
|---|---|
| Int32 | A value that indicates the relative order of the objects being compared. |
Clamp<T>(T, T, T)
Clamps the specified value between the minimum and the maximum.
Declaration
public static T Clamp<T>(this T this, T min, T max)
where T : struct, IComparable
Parameters
| Type | Name | Description |
|---|---|---|
| T | this | The value. |
| T | min | The minimum. |
| T | max | The maximum. |
Returns
| Type | Description |
|---|---|
| T | A value that indicates the relative order of the objects being compared. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to clamp. |
IsBetween<T>(T, T, T)
Determines whether the specified value is between a minimum and a maximum value.
Declaration
public static bool IsBetween<T>(this T this, T min, T max)
where T : struct, IComparable
Parameters
| Type | Name | Description |
|---|---|---|
| T | this | The value. |
| T | min | The minimum. |
| T | max | The maximum. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to check. |
SwapEndianness(UInt64)
Swaps the endianness of an unsigned long to an unsigned integer.
Declaration
public static uint SwapEndianness(this ulong this)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt64 | this | The bytes contained in a long. |
Returns
| Type | Description |
|---|---|
| UInt32 | A 32-bit unsigned integer equivalent to the ulong contained in longBytes. |
ToBytes<T>(T)
Converts a struct to an array of bytes.
Declaration
public static byte[] ToBytes<T>(this T this)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| T | this | The object. |
Returns
| Type | Description |
|---|---|
| Byte[] | A byte array containing the results of encoding the specified set of characters. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of structure to convert. |
ToStruct<T>(Byte[])
Converts an array of bytes into the given struct type.
Declaration
public static T ToStruct<T>(this byte[] this)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | this | The data. |
Returns
| Type | Description |
|---|---|
| T | a struct type derived from convert an array of bytes ref=ToStruct". |
Type Parameters
| Name | Description |
|---|---|
| T | The type of structure to convert. |
ToStruct<T>(Byte[], Int32, Int32)
Converts an array of bytes into the given struct type.
Declaration
public static T ToStruct<T>(this byte[] this, int offset, int length)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | this | The data. |
| Int32 | offset | The offset. |
| Int32 | length | The length. |
Returns
| Type | Description |
|---|---|
| T | A managed object containing the data pointed to by the ptr parameter. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of structure to convert. |