Class BasicExtensions
Various extension methods for core data types.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class BasicExtensions
Methods
| Edit this page 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();
|
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
| Edit this page View SourceEnclosed<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
| Edit this page View SourceGetUserData<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).
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 |
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
| Edit this page View SourceIsNullOrEmpty(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 |
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 |
Type Parameters
| Name | Description |
|---|---|
| T | The type of object to compare. |
Remarks
This method uses Equals(object, object) to check equality between two objects.
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. |