Show / Hide Table of Contents

Class ObjectExtensions

Various extension methods for reference types.

Inheritance
Object
ObjectExtensions
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 ObjectExtensions

Methods

| Improve this Doc 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();
| Improve this Doc View Source

Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>)

Performs decomposition of object into tuple.

Declaration
public static (TResult1, TResult2) Decompose<T, TResult1, TResult2>(this T obj, in ValueFunc<T, TResult1> decomposer1, in ValueFunc<T, TResult2> decomposer2)

    where T : class
Parameters
Type Name Description
T obj

An object to decompose.

ValueFunc<T, TResult1> decomposer1

First decomposition function.

ValueFunc<T, TResult2> decomposer2

Second decomposition function.

Returns
Type Description
ValueTuple<TResult1, TResult2>

Decomposition result.

Type Parameters
Name Description
T

Type of object to decompose.

TResult1

Type of the first decomposition result.

TResult2

Type of the second decomposition result.

| Improve this Doc View Source

Decompose<T, TResult1, TResult2>(T, ValueFunc<T, TResult1>, ValueFunc<T, TResult2>, out TResult1, out TResult2)

Performs decomposition of object into two values.

Declaration
public static void Decompose<T, TResult1, TResult2>(this T obj, in ValueFunc<T, TResult1> decomposer1, in ValueFunc<T, TResult2> decomposer2, out TResult1 result1, out TResult2 result2)

    where T : class
Parameters
Type Name Description
T obj

An object to decompose.

ValueFunc<T, TResult1> decomposer1

First decomposition function.

ValueFunc<T, TResult2> decomposer2

Second decomposition function.

TResult1 result1

First decomposition result.

TResult2 result2

Second decomposition result.

Type Parameters
Name Description
T

Type of object to decompose.

TResult1

Type of the first decomposition result.

TResult2

Type of the second decomposition result.

| Improve this Doc View Source

Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>)

Performs decomposition of object into tuple.

Declaration
public static (TResult1, TResult2) Decompose<T, TResult1, TResult2>(this T obj, Func<T, TResult1> decomposer1, Func<T, TResult2> decomposer2)

    where T : class
Parameters
Type Name Description
T obj

An object to decompose.

Func<T, TResult1> decomposer1

First decomposition function.

Func<T, TResult2> decomposer2

Second decomposition function.

Returns
Type Description
ValueTuple<TResult1, TResult2>

Decomposition result.

Type Parameters
Name Description
T

Type of object to decompose.

TResult1

Type of the first decomposition result.

TResult2

Type of the second decomposition result.

| Improve this Doc View Source

Decompose<T, TResult1, TResult2>(T, Func<T, TResult1>, Func<T, TResult2>, out TResult1, out TResult2)

Performs decomposition of object into two values.

Declaration
public static void Decompose<T, TResult1, TResult2>(this T obj, Func<T, TResult1> decomposer1, Func<T, TResult2> decomposer2, out TResult1 result1, out TResult2 result2)

    where T : class
Parameters
Type Name Description
T obj

An object to decompose.

Func<T, TResult1> decomposer1

First decomposition function.

Func<T, TResult2> decomposer2

Second decomposition function.

TResult1 result1

First decomposition result.

TResult2 result2

Second decomposition result.

Type Parameters
Name Description
T

Type of object to decompose.

TResult1

Type of the first decomposition result.

TResult2

Type of the second decomposition result.

| Improve this Doc 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).

| Improve this Doc View Source

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 value is equal to one of values.

Type Parameters
Name Description
T

The type of object to compare.

Remarks

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

| Improve this Doc View Source

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 value is equal to one of values.

Type Parameters
Name Description
T

The type of object to compare.

Remarks

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

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