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
decoratorIDecorator<object>The IDecorator<T> to extend.
targetTypeTypeThe type of the object to return.
setupAction<ObjectFormattingOptions>The ObjectFormattingOptions which may be configured.
Returns
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
decoratorcannot be null.- AggregateException
The enclosed Object of
decoratorcould 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 = default, Action<ObjectFormattingOptions> setup = null)
Parameters
decoratorIDecorator<object>The IDecorator<T> to extend.
fallbackResultTThe value to return when a conversion is not possible. Default is
defaultofT.setupAction<ObjectFormattingOptions>The ObjectFormattingOptions which may be configured.
Returns
- T
An Object of type
Tequivalent to the enclosed Object of the specifieddecoratorwhen a conversion is possible; otherwisefallbackResultis returned.
Type Parameters
TThe 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.
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
decoratorIDecorator<object>The IDecorator<T> to extend.
setupAction<ObjectFormattingOptions>The ObjectFormattingOptions which may be configured.
Returns
Type Parameters
TThe 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
decoratorcannot be null.- AggregateException
The enclosed Object of
decoratorcould not be converted.
- See Also
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
decoratorIDecorator<object>The IDecorator<T> to extend.
piPropertyInfoThe 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
decoratorIDecorator<TSource>The IDecorator<T> to extend.
traversalFunc<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-traversalis null.