Show / Hide Table of Contents

Class ValueTypeExtensions

Various extensions for value types.

Inheritance
Object
ValueTypeExtensions
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class ValueTypeExtensions

Methods

| Improve this Doc View Source

Add(IntPtr, IntPtr)

Adds two specified native integers.

Declaration
public static IntPtr Add(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The first value to add.

IntPtr y

The second value to add.

Returns
Type Description
IntPtr

The result of adding x and y.

| Improve this Doc View Source

Add(UIntPtr, UIntPtr)

Adds two specified native integers.

Declaration
[CLSCompliant(false)]
public static UIntPtr Add(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The first value to add.

UIntPtr y

The second value to add.

Returns
Type Description
UIntPtr

The result of adding x and y.

| Improve this Doc View Source

AddChecked(IntPtr, IntPtr)

Adds two specified native integers.

Declaration
public static IntPtr AddChecked(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The first value to add.

IntPtr y

The second value to add.

Returns
Type Description
IntPtr

The result of adding x and y.

Exceptions
Type Condition
OverflowException

The result of an operation is outside the bounds of the IntPtr data type.

| Improve this Doc View Source

AddChecked(UIntPtr, UIntPtr)

Adds two specified native integers.

Declaration
[CLSCompliant(false)]
public static UIntPtr AddChecked(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The first value to add.

UIntPtr y

The second value to add.

Returns
Type Description
UIntPtr

The result of adding x and y.

Exceptions
Type Condition
OverflowException

The result of an operation is outside the bounds of the UIntPtr data type.

| Improve this Doc View Source

And(IntPtr, IntPtr)

Computes the bitwise AND of two native integer values.

Declaration
public static IntPtr And(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The first operand.

IntPtr y

The second operand.

Returns
Type Description
IntPtr

The bitwise AND.

| Improve this Doc View Source

And(UIntPtr, UIntPtr)

Computes the bitwise AND of two native integer values.

Declaration
[CLSCompliant(false)]
public static UIntPtr And(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The first operand.

UIntPtr y

The second operand.

Returns
Type Description
UIntPtr

The bitwise AND.

| Improve this Doc View Source

Decrement(IntPtr)

Decrements native integer by 1.

Declaration
public static IntPtr Decrement(this IntPtr value)
Parameters
Type Name Description
IntPtr value

The value to increment.

Returns
Type Description
IntPtr

The decremented value.

| Improve this Doc View Source

Decrement(UIntPtr)

Decrements native integer by 1.

Declaration
[CLSCompliant(false)]
public static UIntPtr Decrement(this UIntPtr value)
Parameters
Type Name Description
UIntPtr value

The value to increment.

Returns
Type Description
UIntPtr

The decremented value.

| Improve this Doc View Source

Divide(IntPtr, IntPtr)

Divides two specified native integers.

Declaration
public static IntPtr Divide(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The dividend.

IntPtr y

The divisor.

Returns
Type Description
IntPtr

The result of dividing x by y.

Exceptions
Type Condition
DivideByZeroException

y is equal to Zero.

| Improve this Doc View Source

Divide(UIntPtr, UIntPtr)

Divides two specified native integers.

Declaration
[CLSCompliant(false)]
public static UIntPtr Divide(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The dividend.

UIntPtr y

The divisor.

Returns
Type Description
UIntPtr

The result of dividing x by y.

| Improve this Doc View Source

EnsureFinite(Double)

Throws ArithmeticException if the value is "not a number" (NaN), positive or negative infinity.

Declaration
public static double EnsureFinite(this double value)
Parameters
Type Name Description
Double value

The value to check.

Returns
Type Description
Double

The value that is equal to value.

Exceptions
Type Condition
ArithmeticException

value is not a number.

| Improve this Doc View Source

EnsureFinite(Single)

Throws ArithmeticException if the value is "not a number" (NaN), positive or negative infinity.

Declaration
public static float EnsureFinite(this float value)
Parameters
Type Name Description
Single value

The value to check.

Returns
Type Description
Single

The value that is equal to value.

Exceptions
Type Condition
ArithmeticException

value is not a number.

| Improve this Doc View Source

GreaterThan(IntPtr, IntPtr)

Determines whether the native integer is greater than the specified value.

Declaration
public static bool GreaterThan(this IntPtr value, IntPtr comparand)
Parameters
Type Name Description
IntPtr value

The value to compare with other value.

IntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is greater than comparand.

| Improve this Doc View Source

GreaterThan(UIntPtr, UIntPtr)

Determines whether the native integer is greater than the specified value.

Declaration
[CLSCompliant(false)]
public static bool GreaterThan(this UIntPtr value, UIntPtr comparand)
Parameters
Type Name Description
UIntPtr value

The value to compare with other value.

UIntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is greater than comparand.

| Improve this Doc View Source

GreaterThanOrEqual(IntPtr, IntPtr)

Determines whether the native integer is greater than or equal to specified value.

Declaration
public static bool GreaterThanOrEqual(this IntPtr value, IntPtr comparand)
Parameters
Type Name Description
IntPtr value

The value to compare with other value.

IntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is greater than or equal to comparand.

| Improve this Doc View Source

GreaterThanOrEqual(UIntPtr, UIntPtr)

Determines whether the native integer is greater than or equal to specified value.

Declaration
[CLSCompliant(false)]
public static bool GreaterThanOrEqual(this UIntPtr value, UIntPtr comparand)
Parameters
Type Name Description
UIntPtr value

The value to compare with other value.

UIntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is greater than or equal to comparand.

| Improve this Doc View Source

Increment(IntPtr)

Increments native integer by 1.

Declaration
public static IntPtr Increment(this IntPtr value)
Parameters
Type Name Description
IntPtr value

The value to increment.

Returns
Type Description
IntPtr

The incremented value.

| Improve this Doc View Source

Increment(UIntPtr)

Increments native integer by 1.

Declaration
[CLSCompliant(false)]
public static UIntPtr Increment(this UIntPtr value)
Parameters
Type Name Description
UIntPtr value

The value to increment.

Returns
Type Description
UIntPtr

The incremented value.

| Improve this Doc View Source

IsOneOf<T>(T, T[])

Checks whether the specified value is equal to one of the specified values.

Declaration
public static bool IsOneOf<T>(this T value, params T[] values)

    where T : struct, IEquatable<T>
Parameters
Type Name Description
T value

The value to compare with other.

T[] values

Candidate objects.

Returns
Type Description
Boolean

true, if value is equal to one of values.

Type Parameters
Name Description
T

The type of object to compare.

Remarks

This method uses Equals(T) to check equality between two values.

| Improve this Doc View Source

IsOneOf<T>(T, IEnumerable<T>)

Checks whether the specified value is equal to one of the specified values.

Declaration
public static bool IsOneOf<T>(this T value, IEnumerable<T> values)

    where T : struct, IEquatable<T>
Parameters
Type Name Description
T value

The value to compare with other.

IEnumerable<T> values

Candidate objects.

Returns
Type Description
Boolean

true, if value is equal to one of values.

Type Parameters
Name Description
T

The type of object to compare.

Remarks

This method uses Equals(T) to check equality between two values.

| Improve this Doc View Source

LeftShift(IntPtr, Int32)

Shifts native integer value to the left by a specified number of bits.

Declaration
public static IntPtr LeftShift(this IntPtr value, int bits)
Parameters
Type Name Description
IntPtr value

The value to shift.

Int32 bits

The numbers of bits to shift.

Returns
Type Description
IntPtr

The modified value.

| Improve this Doc View Source

LeftShift(IntPtr, IntPtr)

Shifts native integer value to the left by a specified number of bits.

Declaration
public static IntPtr LeftShift(this IntPtr value, IntPtr bits)
Parameters
Type Name Description
IntPtr value

The value to shift.

IntPtr bits

The numbers of bits to shift.

Returns
Type Description
IntPtr

The modified value.

| Improve this Doc View Source

LeftShift(UIntPtr, Int32)

Shifts native integer value to the left by a specified number of bits.

Declaration
[CLSCompliant(false)]
public static UIntPtr LeftShift(this UIntPtr value, int bits)
Parameters
Type Name Description
UIntPtr value

The value to shift.

Int32 bits

The numbers of bits to shift.

Returns
Type Description
UIntPtr

The modified value.

| Improve this Doc View Source

LeftShift(UIntPtr, IntPtr)

Shifts native integer value to the left by a specified number of bits.

Declaration
[CLSCompliant(false)]
public static UIntPtr LeftShift(this UIntPtr value, IntPtr bits)
Parameters
Type Name Description
UIntPtr value

The value to shift.

IntPtr bits

The numbers of bits to shift.

Returns
Type Description
UIntPtr

The modified value.

| Improve this Doc View Source

LessThan(IntPtr, IntPtr)

Determines whether the native integer is less than the specified value.

Declaration
public static bool LessThan(this IntPtr value, IntPtr comparand)
Parameters
Type Name Description
IntPtr value

The value to compare with other value.

IntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is less than comparand.

| Improve this Doc View Source

LessThan(UIntPtr, UIntPtr)

Determines whether the native integer is less than the specified value.

Declaration
[CLSCompliant(false)]
public static bool LessThan(this UIntPtr value, UIntPtr comparand)
Parameters
Type Name Description
UIntPtr value

The value to compare with other value.

UIntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is less than comparand.

| Improve this Doc View Source

LessThanOrEqual(IntPtr, IntPtr)

Determines whether the native integer is less than or equal to specified value.

Declaration
public static bool LessThanOrEqual(this IntPtr value, IntPtr comparand)
Parameters
Type Name Description
IntPtr value

The value to compare with other value.

IntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is less than or equal to comparand.

| Improve this Doc View Source

LessThanOrEqual(UIntPtr, UIntPtr)

Determines whether the native integer is less than or equal to specified value.

Declaration
[CLSCompliant(false)]
public static bool LessThanOrEqual(this UIntPtr value, UIntPtr comparand)
Parameters
Type Name Description
UIntPtr value

The value to compare with other value.

UIntPtr comparand

he value that is compared by value to value.

Returns
Type Description
Boolean

true if value is less than or equal to comparand.

| Improve this Doc View Source

Multiply(IntPtr, IntPtr)

Multiplies two specified native integers.

Declaration
public static IntPtr Multiply(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The first value to multiply.

IntPtr y

The second value to mulitply.

Returns
Type Description
IntPtr

The result of multiplying x by y.

| Improve this Doc View Source

Multiply(UIntPtr, UIntPtr)

Multiplies two specified native integers.

Declaration
[CLSCompliant(false)]
public static UIntPtr Multiply(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The first value to multiply.

UIntPtr y

The second value to mulitply.

Returns
Type Description
UIntPtr

The result of multiplying x by y.

| Improve this Doc View Source

MultiplyChecked(IntPtr, IntPtr)

Multiplies two specified native integers.

Declaration
public static IntPtr MultiplyChecked(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The first value to multiply.

IntPtr y

The second value to mulitply.

Returns
Type Description
IntPtr

The result of multiplying x by y.

Exceptions
Type Condition
OverflowException

The result of an operation is outside the bounds of the IntPtr data type.

| Improve this Doc View Source

MultiplyChecked(UIntPtr, UIntPtr)

Multiplies two specified native integers.

Declaration
[CLSCompliant(false)]
public static UIntPtr MultiplyChecked(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The first value to multiply.

UIntPtr y

The second value to mulitply.

Returns
Type Description
UIntPtr

The result of multiplying x by y.

Exceptions
Type Condition
OverflowException

The result of an operation is outside the bounds of the IntPtr data type.

| Improve this Doc View Source

Negate(IntPtr)

Negates native integer value.

Declaration
public static IntPtr Negate(this IntPtr value)
Parameters
Type Name Description
IntPtr value

The value to negate.

Returns
Type Description
IntPtr

The negated value.

| Improve this Doc View Source

OnesComplement(IntPtr)

Computes the bitwise complement of native integer value.

Declaration
public static IntPtr OnesComplement(this IntPtr value)
Parameters
Type Name Description
IntPtr value

The operand.

Returns
Type Description
IntPtr

The result of bitwise complement.

| Improve this Doc View Source

OnesComplement(UIntPtr)

Computes the bitwise complement of native integer value.

Declaration
[CLSCompliant(false)]
public static UIntPtr OnesComplement(this UIntPtr value)
Parameters
Type Name Description
UIntPtr value

The operand.

Returns
Type Description
UIntPtr

The result of bitwise complement.

| Improve this Doc View Source

Or(IntPtr, IntPtr)

Computes the bitwise OR of two native integer values.

Declaration
public static IntPtr Or(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The first operand.

IntPtr y

The second operand.

Returns
Type Description
IntPtr

The bitwise OR.

| Improve this Doc View Source

Or(UIntPtr, UIntPtr)

Computes the bitwise OR of two native integer values.

Declaration
[CLSCompliant(false)]
public static UIntPtr Or(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The first operand.

UIntPtr y

The second operand.

Returns
Type Description
UIntPtr

The bitwise OR.

| Improve this Doc View Source

Remainder(IntPtr, IntPtr)

Divides two values and returns the remainder.

Declaration
public static IntPtr Remainder(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The dividend.

IntPtr y

The divisor.

Returns
Type Description
IntPtr

The remainder.

Exceptions
Type Condition
DivideByZeroException

y is equal to Zero.

| Improve this Doc View Source

Remainder(UIntPtr, UIntPtr)

Divides two values and returns the remainder.

Declaration
[CLSCompliant(false)]
public static UIntPtr Remainder(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The dividend.

UIntPtr y

The divisor.

Returns
Type Description
UIntPtr

The remainder.

Exceptions
Type Condition
DivideByZeroException

y is equal to Zero.

| Improve this Doc View Source

RightShift(IntPtr, Int32)

Shifts native integer value to the right by a specified number of bits.

Declaration
public static IntPtr RightShift(this IntPtr value, int bits)
Parameters
Type Name Description
IntPtr value

The value to shift.

Int32 bits

The numbers of bits to shift.

Returns
Type Description
IntPtr

The modified value.

| Improve this Doc View Source

RightShift(IntPtr, IntPtr)

Shifts native integer value to the right by a specified number of bits.

Declaration
public static IntPtr RightShift(this IntPtr value, IntPtr bits)
Parameters
Type Name Description
IntPtr value

The value to shift.

IntPtr bits

The numbers of bits to shift.

Returns
Type Description
IntPtr

The modified value.

| Improve this Doc View Source

RightShift(UIntPtr, Int32)

Shifts native integer value to the right by a specified number of bits.

Declaration
[CLSCompliant(false)]
public static UIntPtr RightShift(this UIntPtr value, int bits)
Parameters
Type Name Description
UIntPtr value

The value to shift.

Int32 bits

The numbers of bits to shift.

Returns
Type Description
UIntPtr

The modified value.

| Improve this Doc View Source

RightShift(UIntPtr, IntPtr)

Shifts native integer value to the right by a specified number of bits.

Declaration
[CLSCompliant(false)]
public static UIntPtr RightShift(this UIntPtr value, IntPtr bits)
Parameters
Type Name Description
UIntPtr value

The value to shift.

IntPtr bits

The numbers of bits to shift.

Returns
Type Description
UIntPtr

The modified value.

| Improve this Doc View Source

Subtract(IntPtr, IntPtr)

Subtracts two native integers.

Declaration
public static IntPtr Subtract(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The minuend.

IntPtr y

The subtrahend.

Returns
Type Description
IntPtr

The result of subtracting y from x.

| Improve this Doc View Source

Subtract(UIntPtr, UIntPtr)

Subtracts two native integers.

Declaration
[CLSCompliant(false)]
public static UIntPtr Subtract(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The minuend.

UIntPtr y

The subtrahend.

Returns
Type Description
UIntPtr

The result of subtracting y from x.

| Improve this Doc View Source

SubtractChecked(IntPtr, IntPtr)

Subtracts two native integers.

Declaration
public static IntPtr SubtractChecked(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The minuend.

IntPtr y

The subtrahend.

Returns
Type Description
IntPtr

The result of subtracting y from x.

Exceptions
Type Condition
OverflowException

The result of an operation is outside the bounds of the IntPtr data type.

| Improve this Doc View Source

SubtractChecked(UIntPtr, UIntPtr)

Subtracts two native integers.

Declaration
[CLSCompliant(false)]
public static UIntPtr SubtractChecked(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The minuend.

UIntPtr y

The subtrahend.

Returns
Type Description
UIntPtr

The result of subtracting y from x.

Exceptions
Type Condition
OverflowException

The result of an operation is outside the bounds of the UIntPtr data type.

| Improve this Doc View Source

ToBoolean(Int32)

Converts Int32 into Boolean.

Declaration
public static bool ToBoolean(this int value)
Parameters
Type Name Description
Int32 value

The value to convert.

Returns
Type Description
Boolean

true if value != 0; otherwise, false.

| Improve this Doc View Source

ToByte(Boolean)

Converts Boolean into Byte.

Declaration
public static byte ToByte(this bool value)
Parameters
Type Name Description
Boolean value

The value to convert.

Returns
Type Description
Byte

Byte representation of value.

| Improve this Doc View Source

ToInt32(Boolean)

Converts Boolean into Int32.

Declaration
public static int ToInt32(this bool value)
Parameters
Type Name Description
Boolean value

The value to convert.

Returns
Type Description
Int32

Int32 representation of value.

| Improve this Doc View Source

ToIntPtr(UIntPtr)

Converts UIntPtr into IntPtr.

Declaration
[CLSCompliant(false)]
public static IntPtr ToIntPtr(this UIntPtr value)
Parameters
Type Name Description
UIntPtr value

The value to convert.

Returns
Type Description
IntPtr

The converted value.

| Improve this Doc View Source

ToIntPtrChecked(UIntPtr)

Converts UIntPtr into IntPtr respecting overflow.

Declaration
[CLSCompliant(false)]
public static IntPtr ToIntPtrChecked(this UIntPtr value)
Parameters
Type Name Description
UIntPtr value

The value to convert.

Returns
Type Description
IntPtr

The converted value.

Exceptions
Type Condition
OverflowException

value is greater than the maximum positive signed native integer.

| Improve this Doc View Source

ToUIntPtr(IntPtr)

Converts IntPtr into UIntPtr.

Declaration
[CLSCompliant(false)]
public static UIntPtr ToUIntPtr(this IntPtr value)
Parameters
Type Name Description
IntPtr value

The value to convert.

Returns
Type Description
UIntPtr

The converted value.

| Improve this Doc View Source

ToUIntPtrChecked(IntPtr)

Converts UIntPtr into IntPtr respecting overflow.

Declaration
[CLSCompliant(false)]
public static UIntPtr ToUIntPtrChecked(this IntPtr value)
Parameters
Type Name Description
IntPtr value

The value to convert.

Returns
Type Description
UIntPtr

The converted value.

Exceptions
Type Condition
OverflowException

value is less than zero.

| Improve this Doc View Source

Truncate(Int64)

Truncates 64-bit signed integer.

Declaration
public static int Truncate(this long value)
Parameters
Type Name Description
Int64 value

The value to truncate.

Returns
Type Description
Int32

MaxValue if value is greater than MaxValue; otherwise, cast value to Int32.

| Improve this Doc View Source

TryGetValue<T>(Nullable<T>, out T)

Attempts to get value from nullable container.

Declaration
public static bool TryGetValue<T>(this T? nullable, out T value)

    where T : struct
Parameters
Type Name Description
Nullable<T> nullable

Nullable value.

T value

Underlying value.

Returns
Type Description
Boolean

true if nullable is not null; otherwise, false.

Type Parameters
Name Description
T

The underlying value type of the nullable type.

| Improve this Doc View Source

Xor(IntPtr, IntPtr)

Computes the bitwise XOR of two native integer values.

Declaration
public static IntPtr Xor(this IntPtr x, IntPtr y)
Parameters
Type Name Description
IntPtr x

The first operand.

IntPtr y

The second operand.

Returns
Type Description
IntPtr

The bitwise XOR.

| Improve this Doc View Source

Xor(UIntPtr, UIntPtr)

Computes the bitwise XOR of two native integer values.

Declaration
[CLSCompliant(false)]
public static UIntPtr Xor(this UIntPtr x, UIntPtr y)
Parameters
Type Name Description
UIntPtr x

The first operand.

UIntPtr y

The second operand.

Returns
Type Description
UIntPtr

The bitwise XOR.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX