Class ObjectExtensions
Various extension methods for reference types.
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class ObjectExtensions : object
Methods
| Improve this Doc View SourceDecompose<T, R1, R2>(T, Func<T, R1>, Func<T, R2>)
Performs decomposition of object into tuple.
Declaration
public static (R1, R2) Decompose<T, R1, R2>(this T obj, Func<T, R1> decomposer1, Func<T, R2> decomposer2)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | An object to decompose. |
DotNext.Func<T, R1> | decomposer1 | First decomposition function. |
DotNext.Func<T, R2> | decomposer2 | Second decomposition function. |
Returns
Type | Description |
---|---|
ValueTuple<R1, R2> | Decomposition result. |
Type Parameters
Name | Description |
---|---|
T | Type of object to decompose. |
R1 | Type of the first decomposition result. |
R2 | Type of the second decomposition result. |
Decompose<T, R1, R2>(T, Func<T, R1>, Func<T, R2>, out R1, out R2)
Performs decomposition of object into two values.
Declaration
public static void Decompose<T, R1, R2>(this T obj, Func<T, R1> decomposer1, Func<T, R2> decomposer2, out R1 result1, out R2 result2)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | An object to decompose. |
DotNext.Func<T, R1> | decomposer1 | First decomposition function. |
DotNext.Func<T, R2> | decomposer2 | Second decomposition function. |
R1 | result1 | First decomposition result. |
R2 | result2 | Second decomposition result. |
Type Parameters
Name | Description |
---|---|
T | Type of object to decompose. |
R1 | Type of the first decomposition result. |
R2 | Type of the second decomposition result. |
Decompose<T, R1, R2>(T, ValueFunc<T, R1>, ValueFunc<T, R2>)
Performs decomposition of object into tuple.
Declaration
public static (R1, R2) Decompose<T, R1, R2>(this T obj, in ValueFunc<T, R1> decomposer1, in ValueFunc<T, R2> decomposer2)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | An object to decompose. |
ValueFunc<T, R1> | decomposer1 | First decomposition function. |
ValueFunc<T, R2> | decomposer2 | Second decomposition function. |
Returns
Type | Description |
---|---|
ValueTuple<R1, R2> | Decomposition result. |
Type Parameters
Name | Description |
---|---|
T | Type of object to decompose. |
R1 | Type of the first decomposition result. |
R2 | Type of the second decomposition result. |
Decompose<T, R1, R2>(T, ValueFunc<T, R1>, ValueFunc<T, R2>, out R1, out R2)
Performs decomposition of object into two values.
Declaration
public static void Decompose<T, R1, R2>(this T obj, in ValueFunc<T, R1> decomposer1, in ValueFunc<T, R2> decomposer2, out R1 result1, out R2 result2)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | obj | An object to decompose. |
ValueFunc<T, R1> | decomposer1 | First decomposition function. |
ValueFunc<T, R2> | decomposer2 | Second decomposition function. |
R1 | result1 | First decomposition result. |
R2 | result2 | Second decomposition result. |
Type Parameters
Name | Description |
---|---|
T | Type of object to decompose. |
R1 | Type of the first decomposition result. |
R2 | Type of the second decomposition result. |
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 |
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)
IsOneOf<T>(T, T[])
Checks whether the specified object is equal to one of the specified objects.
Declaration
public static bool IsOneOf<T>(this T value, params T[] values)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The object to compare with other. |
T[] | values | Candidate objects. |
Returns
Type | Description |
---|---|
Boolean | true, if |
Type Parameters
Name | Description |
---|---|
T | The type of object to compare. |
Remarks
This method uses
IsOneOf<T>(T, IEnumerable<T>)
Checks whether the specified object is equal to one of the specified objects.
Declaration
public static bool IsOneOf<T>(this T value, IEnumerable<T> values)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | The object to compare with other. |
IEnumerable<T> | values | Candidate objects. |
Returns
Type | Description |
---|---|
Boolean | true, if |
Type Parameters
Name | Description |
---|---|
T | The type of object to compare. |
Remarks
This method uses