/// <summary> /// Transforms the changeset into a different type using the specified transform function. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <typeparam name="TDestination">The type of the destination.</typeparam> /// <param name="source">The source.</param> /// <param name="transformer">The transformer.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// source /// or /// transformer /// </exception> public static IChangeSet <TDestination> Transform <TSource, TDestination>([NotNull] this IChangeSet <TSource> source, [NotNull] Func <TSource, TDestination> transformer) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (transformer == null) { throw new ArgumentNullException(nameof(transformer)); } var changes = source.Select(change => { if (change.Type == ChangeType.Item) { return(new Change <TDestination>(change.Reason, transformer(change.Item.Current), OptionExtensions.Convert(change.Item.Previous, transformer), change.Item.CurrentIndex, change.Item.PreviousIndex)); } return(new Change <TDestination>(change.Reason, change.Range.Select(transformer), change.Range.Index)); }); return(new ChangeSet <TDestination>(changes)); }
public IObservable <IChangeSet <TDestination, TKey> > Run() { return(_source.Select(changes => { var transformed = Enumerable.Select <Change <TSource, TKey>, Change <TDestination, TKey> >(changes, change => new Change <TDestination, TKey>(change.Reason, change.Key, _converter(change.Current), OptionExtensions.Convert(change.Previous, _converter), change.CurrentIndex, change.PreviousIndex)); return new ChangeSet <TDestination, TKey>(transformed); })); }