Table of Contents

Class ObjectExtensions

Namespace
Cuemon.Extensions
Assembly
Cuemon.Extensions.Core.dll

Extension methods for the Object class.

public static class ObjectExtensions
Inheritance
ObjectExtensions

Methods

Adjust<T>(T, Func<T, T>)

Adjust the specified value with the function delegate converter.

public static T Adjust<T>(this T value, Func<T, T> converter)

Parameters

value T

The value to convert.

converter Func<T, T>

The function delegate that will convert the specified value.

Returns

T

The value in its original or converted form.

Type Parameters

T

The type of the value to convert.

Remarks

This is thought to be a more severe change than the one provided by Alter<T>(T, Action<T>) (e.g., potentially convert the entire value to a new instance).

Alter<T>(T, Action<T>)

Adjust the specified value with the modifier delegate.

public static T Alter<T>(this T value, Action<T> modifier)

Parameters

value T

The value to adjust.

modifier Action<T>

The delegate that will adjust the specified value.

Returns

T

The value in its original or adjusted form.

Type Parameters

T

The type of the value to adjust.

Remarks

This is thought to be a more relaxed change than the one provided by Adjust<T>(T, Func<T, T>) (e.g., applying changes only to the current value).

As(Object, Type, Action<ObjectFormattingOptions>)

Attempts to converts the specified value to the given targetType.

public static object As(this object value, Type targetType, Action<ObjectFormattingOptions> setup = null)

Parameters

value Object

The object to convert the underlying type.

targetType Type

The type of the object to return.

setup Action<ObjectFormattingOptions>

The ObjectFormattingOptions which may be configured.

Returns

Object

An Object of type targetType equivalent to value.

Remarks

What differs from the ChangeType(Object, Type) is, that this converter supports generics and enums. Fallback uses TypeDescriptor and checks if the underlying IFormatProvider of FormatProvider is a CultureInfo, then this will be used in the conversion together with DescriptorContext.

Exceptions

ArgumentNullException

value cannot be null - or - targetType cannot be null.

AggregateException

value could not be converted.

See Also

As<T>(Object, T, Action<ObjectFormattingOptions>)

Attempts to converts the specified value to a given type. If the conversion is not possible the result is set to fallbackResult.

public static T As<T>(this object value, T fallbackResult = null, Action<ObjectFormattingOptions> setup = null)

Parameters

value Object

The object to convert the underlying type.

fallbackResult T

The value to return when a conversion is not possible. Default is default of T.

setup Action<ObjectFormattingOptions>

The ObjectFormattingOptions which may be configured.

Returns

T

The value converted to the specified T.

Type Parameters

T

The type of the object to return.

As<T, TResult>(T, Func<T, TResult>)

Converts the specified value to a value of TResult.

public static TResult As<T, TResult>(this T value, Func<T, TResult> converter)

Parameters

value T

The value to convert.

converter Func<T, TResult>

The function delegate that will perform the conversion.

Returns

TResult

The value converted to the specified T.

Type Parameters

T

The type of the value to convert.

TResult

The type of the value to return.

Exceptions

ArgumentNullException

value cannot be null.

GetHashCode32<T>(IEnumerable<T>)

Computes a suitable hash code from the specified sequence of convertibles.

public static int GetHashCode32<T>(this IEnumerable<T> convertibles)
    where T : IConvertible

Parameters

convertibles IEnumerable<T>

A sequence of objects implementing the IConvertible interface.

Returns

Int32

A 32-bit signed integer that is the hash code of convertibles.

Type Parameters

T

GetHashCode64<T>(IEnumerable<T>)

Computes a suitable hash code from the specified sequence of convertibles.

public static long GetHashCode64<T>(this IEnumerable<T> convertibles)
    where T : IConvertible

Parameters

convertibles IEnumerable<T>

A sequence of objects implementing the IConvertible interface.

Returns

Int64

A 64-bit signed integer that is the hash code of convertibles.

Type Parameters

T

IsNullable<T>(T)

Determines whether the specified source is a nullable ValueType.

public static bool IsNullable<T>(this T _)

Parameters

_ T

The source type to check for nullable ValueType.

Returns

Boolean

true if the specified source is nullable; otherwise, false.

Type Parameters

T

The type of the _ of T.

ToDelimitedString<T>(IEnumerable<T>, Action<DelimitedStringOptions<T>>)

Converts the specified source to a string of delimited values.

public static string ToDelimitedString<T>(this IEnumerable<T> source, Action<DelimitedStringOptions<T>> setup = null)

Parameters

source IEnumerable<T>

A sequence of elements to be converted.

setup Action<DelimitedStringOptions<T>>

The DelimitedStringOptions<T> which may be configured.

Returns

String

A String of delimited values.

Type Parameters

T

The type of the elements of the sequence to convert.

Exceptions

ArgumentNullException

source cannot be null.

UseWrapper<T>(T, Action<IDictionary<String, Object>>)

Wrap and extend an existing object of T with additional data.

public static IWrapper<T> UseWrapper<T>(this T instance, Action<IDictionary<string, object>> extender = null)

Parameters

instance T

The instance to wrap and extend.

extender Action<IDictionary<String, Object>>

The delegate that provides an easy way of supplying additional data to an object.

Returns

IWrapper<T>

An implementation of IWrapper<T> encapsulating the specified instance.

Type Parameters

T

The type of the object to extend.

UseWrapper<T>(T, MemberInfo, Action<IDictionary<String, Object>>)

Wrap and extend an existing object of T with additional data.

public static IWrapper<T> UseWrapper<T>(this T instance, MemberInfo memberReference, Action<IDictionary<string, object>> extender = null)

Parameters

instance T

The instance to wrap and extend.

memberReference MemberInfo

The optional member reference to assign MemberReference.

extender Action<IDictionary<String, Object>>

The delegate that provides an easy way of supplying additional data to an object.

Returns

IWrapper<T>

An implementation of IWrapper<T> encapsulating the specified instance.

Type Parameters

T

The type of the object to extend.