/// <summary> /// When destructuring objects, transform instances of the specified type with /// the provided function. /// </summary> /// <param name="transformation">Function mapping instances of <typeparamref name="TValue"/> /// to an alternative representation.</param> /// <typeparam name="TValue">Type of values to transform.</typeparam> /// <returns>Configuration object allowing method chaining.</returns> /// <exception cref="ArgumentNullException"></exception> public LoggerConfiguration ByTransforming <TValue>(Func <TValue, object> transformation) { if (transformation == null) { throw new ArgumentNullException("transformation"); } var policy = new ProjectedDestructuringPolicy(t => t == typeof(TValue), o => transformation((TValue)o)); return(With(policy)); }
/// <summary> /// When destructuring objects, transform instances of the specified type with /// the provided function, if the predicate returns true. Be careful to avoid any /// intensive work in the predicate, as it can slow down the pipeline significantly. /// </summary> /// <param name="predicate">A predicate used to determine if the transform applies to /// a specific type of value</param> /// <param name="transformation">Function mapping instances of <typeparamref name="TValue"/> /// to an alternative representation.</param> /// <typeparam name="TValue">Type of values to transform.</typeparam> /// <returns>Configuration object allowing method chaining.</returns> /// <exception cref="ArgumentNullException"></exception> public LoggerConfiguration ByTransformingWhere <TValue>( Func <Type, bool> predicate, Func <TValue, object> transformation) { if (transformation == null) { throw new ArgumentNullException(nameof(transformation)); } var policy = new ProjectedDestructuringPolicy(predicate, o => transformation((TValue)o)); return(With(policy)); }