Table of Contents

Class ObjectDecoratorExtensions

Namespace
Cuemon
Assembly
Cuemon.Core.dll

Extension methods for the Object class hidden behind the IDecorator<T> interface.

public static class ObjectDecoratorExtensions
Inheritance
ObjectDecoratorExtensions

Methods

ChangeType(IDecorator<Object>, Type, Action<ObjectFormattingOptions>)

Returns an Object of a specified targetType whose value is equivalent to the enclosed Object of the specified decorator.

public static object ChangeType(this IDecorator<object> decorator, Type targetType, Action<ObjectFormattingOptions> setup = null)

Parameters

decorator IDecorator<Object>

The IDecorator<T> to extend.

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 the enclosed Object of the specified decorator.

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

decorator cannot be null.

AggregateException

The enclosed Object of decorator could not be converted.

See Also

ChangeType<T>(IDecorator<Object>, Action<ObjectFormattingOptions>)

Returns an Object of the specified T whose value is equivalent to the enclosed Object of the specified decorator.

public static T ChangeType<T>(this IDecorator<object> decorator, Action<ObjectFormattingOptions> setup = null)

Parameters

decorator IDecorator<Object>

The IDecorator<T> to extend.

setup Action<ObjectFormattingOptions>

The ObjectFormattingOptions which may be configured.

Returns

T

An Object of type T equivalent to the enclosed Object of the specified decorator.

Type Parameters

T

The type of the object to return.

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

decorator cannot be null.

AggregateException

The enclosed Object of decorator could not be converted.

See Also

ChangeTypeOrDefault<T>(IDecorator<Object>, T, Action<ObjectFormattingOptions>)

Returns an Object of the specified T whose value is equivalent to the enclosed Object of the specified decorator.

public static T ChangeTypeOrDefault<T>(this IDecorator<object> decorator, T fallbackResult = null, Action<ObjectFormattingOptions> setup = null)

Parameters

decorator IDecorator<Object>

The IDecorator<T> to extend.

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

An Object of type T equivalent to the enclosed Object of the specified decorator when a conversion is possible; otherwise fallbackResult is returned.

Type Parameters

T

The type of the object to return.

Remarks

This method first checks if the enclosed Object of the specified decorator is compatible with T; if incompatible the method continues with ChangeType<T>(IDecorator<Object>, Action<ObjectFormattingOptions>) for the operation.

DefaultPropertyValueResolver(IDecorator<Object>, PropertyInfo)

Resolves the default value of a property from the enclosed object of the specified decorator.

public static object DefaultPropertyValueResolver(this IDecorator<object> decorator, PropertyInfo pi)

Parameters

decorator IDecorator<Object>

The IDecorator<T> to extend.

pi PropertyInfo

The PropertyInfo of the property to resolve the value for.

Returns

Object

The value of the property if the enclosed object is not null; otherwise, null.

Remarks

This API supports the product infrastructure and is not intended to be used directly from your code.

TraverseWhileNotEmpty<TSource>(IDecorator<TSource>, Func<TSource, IEnumerable<TSource>>)

Invokes the specified traversal path of the enclosed object of the specified decorator until obstructed by an empty sequence.

public static IEnumerable<TSource> TraverseWhileNotEmpty<TSource>(this IDecorator<TSource> decorator, Func<TSource, IEnumerable<TSource>> traversal)
    where TSource : class

Parameters

decorator IDecorator<TSource>

The IDecorator<T> to extend.

traversal Func<TSource, IEnumerable<TSource>>

The function delegate that is invoked until the traveled path is obstructed by an empty sequence.

Returns

IEnumerable<TSource>

An IEnumerable<T> sequence equal to the traveled path of the enclosed object of the specified decorator.

Type Parameters

TSource

Exceptions

ArgumentNullException

decorator -or- traversal is null.

See Also