Class ObjectDecoratorExtensions
Extension methods for the Object class tailored to adhere the decorator pattern.
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class ObjectDecoratorExtensions
Methods
| Improve this Doc View SourceAdjust<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 |
Returns
Type | Description |
---|---|
T | The enclosed |
Type Parameters
Name | Description |
---|---|
T | The type of the value to adjust. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
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 |
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 |
|
AggregateException | The enclosed Object of |
See Also
| Improve this Doc View SourceChangeType<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 |
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 |
|
AggregateException | The enclosed Object of |
See Also
| Improve this Doc View SourceChangeTypeOrDefault<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 |
Action<ObjectFormattingOptions> | setup | The ObjectFormattingOptions which may be configured. |
Returns
Type | Description |
---|---|
T | An Object of type |
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.