Show / Hide Table of Contents

Class BasicExtensions

Various extension methods for core data types.

Inheritance
object
BasicExtensions
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 BasicExtensions

Methods

| Edit this page View Source

As<T>(T)

Reinterprets object reference.

Declaration
public static T As<T>(this T obj) where T : class?
Parameters
Type Name Description
T obj

The object reference to reinterpret.

Returns
Type Description
T

The reinterpreted obj reference.

Type Parameters
Name Description
T

The target type.

Remarks

This method can be used to get access to the explicitly implemented interface methods.

Examples
MemoryManager<T> manager;
manager.As<IDisposable>().Dispose();
| Edit this page View Source

Disclosed<T>(T)

Creates disclosed range endpoint.

Declaration
public static DisclosedEndpoint<T> Disclosed<T>(this T value) where T : IComparable<T>
Parameters
Type Name Description
T value

The endpoint value.

Returns
Type Description
DisclosedEndpoint<T>

The range endpoint.

Type Parameters
Name Description
T

The type of the endpoint.

See Also
IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
| Edit this page View Source

Enclosed<T>(T)

Creates enclosed range endpoint.

Declaration
public static EnclosedEndpoint<T> Enclosed<T>(this T value) where T : IComparable<T>
Parameters
Type Name Description
T value

The endpoint value.

Returns
Type Description
EnclosedEndpoint<T>

The range endpoint.

Type Parameters
Name Description
T

The type of the endpoint.

See Also
IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
| Edit this page View Source

GetUserData<T>(T)

Provides ad-hoc approach to associate some data with the object without modification of it.

Declaration
public static UserDataStorage GetUserData<T>(this T obj) where T : class
Parameters
Type Name Description
T obj

Target object.

Returns
Type Description
UserDataStorage

User data storage.

Type Parameters
Name Description
T

The type of the object.

Remarks

This method allows to associate arbitrary user data with any object. User data storage is not a part of object type declaration. Modification of user data doesn't cause modification of internal state of the object. The storage is associated with the object reference. Any user data are transient and can't be passed across process boundaries (i.e. serialization is not supported).

| Edit this page View Source

IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)

Determines whether the specified value is in the specified range.

Declaration
public static bool IsBetween<T, TLowerBound, TUpperBound>(this T value, TLowerBound lowerBound, TUpperBound upperBound) where T : notnull where TLowerBound : IRangeEndpoint<T> where TUpperBound : IRangeEndpoint<T>
Parameters
Type Name Description
T value

The value to compare.

TLowerBound lowerBound

The lower bound.

TUpperBound upperBound

The upper bound.

Returns
Type Description
bool

true if value is in the specified range; otherwise, false.

Type Parameters
Name Description
T

The type of the value.

TLowerBound

The lower bound type.

TUpperBound

The upper bound type.

Examples

The following example demonstrates how to check whether the value is in range [0..1).

double x;
IsBetween(x, 0D.Enclosed(), 1D.Disclosed());
See Also
Enclosed<T>(T)
Disclosed<T>(T)
| Edit this page View Source

IsNullOrEmpty(Array?)

Indicates that array is null or empty.

Declaration
public static bool IsNullOrEmpty(this Array? array)
Parameters
Type Name Description
Array array

The array to check.

Returns
Type Description
bool

true, if array is null or empty.

| Edit this page View Source

IsOneOf<T>(T, ReadOnlySpan<T>)

Checks whether the specified object is equal to one of the specified objects.

Declaration
public static bool IsOneOf<T>(this T value, ReadOnlySpan<T> candidates)
Parameters
Type Name Description
T value

The object to compare with other.

ReadOnlySpan<T> candidates

Candidate objects.

Returns
Type Description
bool

true, if value is equal to one of candidates.

Type Parameters
Name Description
T

The type of object to compare.

Remarks

This method uses Equals(object, object) to check equality between two objects.

| Edit this page View Source

TryGetValue<T>(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
T? nullable

Nullable value.

T value

Underlying value.

Returns
Type Description
bool

true if nullable is not null; otherwise, false.

Type Parameters
Name Description
T

The underlying value type of the nullable type.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾