Class BasicExtensions
Various extension methods for core data types.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class BasicExtensions
Methods
View SourceAs<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 |
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();
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, allows ref struct where TLowerBound : IRangeEndpoint<T>, allows ref struct where TUpperBound : IRangeEndpoint<T>, allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to compare. |
| TLowerBound | lowerBound | The lower bound. |
| TUpperBound | upperBound | The upper bound. |
Returns
| Type | Description |
|---|---|
| bool |
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
View SourceIsExactTypeOf<T>(object?)
Checks whether the specified object is exactly of the specified type.
Declaration
public static bool IsExactTypeOf<T>(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to test. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
IsOneOf<T>(T, params ReadOnlySpan<T>)
Checks whether the specified object is equal to one of the specified objects.
Declaration
public static bool IsOneOf<T>(this T value, params ReadOnlySpan<T> candidates)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The object to compare with the others. |
| ReadOnlySpan<T> | candidates | Candidate objects. |
Returns
| Type | Description |
|---|---|
| bool | true, if |
Type Parameters
| Name | Description |
|---|---|
| T | The type of object to compare. |
Remarks
This method uses Equals(object, object) to check equality between two objects.
IsTypeOf<T>(object?)
Checks whether the specified object is of type T.
Declaration
public static bool IsTypeOf<T>(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to check. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
KeepAlive<T>(ref readonly T)
Keeps the reference to the value type alive.
Declaration
public static void KeepAlive<T>(ref readonly T location) where T : struct, allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| T | location | A location of the object. |
Type Parameters
| Name | Description |
|---|---|
| T | The value type. |
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 |
Type Parameters
| Name | Description |
|---|---|
| T | The underlying value type of the nullable type. |
get_Disclosed<T>(T)
Creates disclosed range endpoint.
Declaration
public static DisclosedEndpoint<T> get_Disclosed<T>(T value) where T : notnull, IComparable<T>, allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| T | value |
Returns
| Type | Description |
|---|---|
| DisclosedEndpoint<T> | The range endpoint. |
Type Parameters
| Name | Description |
|---|---|
| T |
See Also
View Sourceget_Enclosed<T>(T)
Creates enclosed range endpoint.
Declaration
public static EnclosedEndpoint<T> get_Enclosed<T>(T value) where T : notnull, IComparable<T>, allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| T | value |
Returns
| Type | Description |
|---|---|
| EnclosedEndpoint<T> | The range endpoint. |
Type Parameters
| Name | Description |
|---|---|
| T |
See Also
View Sourceget_Unbounded<T>()
Gets the endpoint that represents the infinity.
Declaration
public static IRangeEndpoint<T> get_Unbounded<T>() where T : notnull, IComparable<T>, allows ref struct
Returns
| Type | Description |
|---|---|
| IRangeEndpoint<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
get_UserData<T>(T)
Provides ad-hoc approach to associate some data with the object without modification of it.
Declaration
public static UserDataStorage get_UserData<T>(T obj) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | obj |
Returns
| Type | Description |
|---|---|
| UserDataStorage | User data storage. |
Type Parameters
| Name | Description |
|---|---|
| T |
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).