Show / Hide Table of Contents

Class ObjectDecoratorExtensions

Extension methods for the Object class tailored to adhere the decorator pattern.

Inheritance
Object
ObjectDecoratorExtensions
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class ObjectDecoratorExtensions

Methods

| Improve this Doc View Source

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

Adjust the enclosed T of the decorator with the function delegate tweaker.

Declaration
public static T Adjust<T>(this IDecorator<T> decorator, Func<T, T> tweaker)
Parameters
Type Name Description
IDecorator<T> decorator

The IDecorator<T> to extend.

Func<T, T> tweaker

The function delegate that will adjust the enclosed T of the decorator.

Returns
Type Description
T

The enclosed T of the decorator in its original or adjusted form.

Type Parameters
Name Description
T

The type of the value to adjust.

Exceptions
Type Condition
ArgumentNullException

decorator cannot be null.

| Improve this Doc View Source

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.

Declaration
public static object ChangeType(this IDecorator<object> decorator, Type targetType, Action<ObjectFormattingOptions> setup = null)
Parameters
Type Name Description
IDecorator<Object> decorator

The IDecorator<T> to extend.

Type targetType

The type of the object to return.

Action<ObjectFormattingOptions> setup

The ObjectFormattingOptions which may be configured.

Returns
Type Description
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
Type Condition
ArgumentNullException

decorator cannot be null.

AggregateException

The enclosed Object of decorator could not be converted.

See Also
ChangeType(Object, Type)
GetConverter(Type)
| Improve this Doc View Source

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.

Declaration
public static T ChangeType<T>(this IDecorator<object> decorator, Action<ObjectFormattingOptions> setup = null)
Parameters
Type Name Description
IDecorator<Object> decorator

The IDecorator<T> to extend.

Action<ObjectFormattingOptions> setup

The ObjectFormattingOptions which may be configured.

Returns
Type Description
T

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

Type Parameters
Name Description
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
Type Condition
ArgumentNullException

decorator cannot be null.

AggregateException

The enclosed Object of decorator could not be converted.

See Also
ChangeType(Object, Type)
GetConverter(Type)
| Improve this Doc View Source

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.

Declaration
public static T ChangeTypeOrDefault<T>(this IDecorator<object> decorator, T fallbackResult = null, Action<ObjectFormattingOptions> setup = null)
Parameters
Type Name Description
IDecorator<Object> decorator

The IDecorator<T> to extend.

T fallbackResult

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

Action<ObjectFormattingOptions> setup

The ObjectFormattingOptions which may be configured.

Returns
Type Description
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
Name Description
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.

See Also

IDecorator<T>
Decorator<T>
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright 2008-2022 Geekle. All rights reserved. Code with passion and love; deploy with confidence. 👨‍💻️🔥❤️🚀😎
Generated by DocFX