<commit_before>﻿using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Windows;

namespace ReactiveUIMicro
{
    public static class WhenAnyShim
    {
        public static IObservable<TVal> WhenAny<TSender, TTarget, TVal>(this TSender This, Expression<Func<TSender, TTarget>> property, Func<IObservedChange<TSender, TTarget>, TVal> selector)
            where TSender : IReactiveNotifyPropertyChanged
        {
            var propName = Reflection.SimpleExpressionToPropertyName(property);
            var getter = Reflection.GetValueFetcherForProperty<TSender>(propName);

            return This.Changed
                .Where(x => x.PropertyName == propName)
                .Select(_ => new ObservedChange<TSender, TTarget>() {
                    Sender = This,
                    PropertyName = propName,
                    Value = (TTarget)getter(This),
                })
                .StartWith(new ObservedChange<TSender, TTarget>() { Sender = This, PropertyName = propName, Value = (TTarget)getter(This) })
                .Select(selector);
        }
    }<commit_msg>Fix casting error in WhenAny shim<commit_after>﻿using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Windows;

namespace ReactiveUIMicro
{
    public static class WhenAnyShim
    {
        public static IObservable<TVal> WhenAny<TSender, TTarget, TVal>(this TSender This, Expression<Func<TSender, TTarget>> property, Func<IObservedChange<TSender, TTarget>, TVal> selector)
            where TSender : IReactiveNotifyPropertyChanged
        {
            var propName = Reflection.SimpleExpressionToPropertyName(property);
            var getter = Reflection.GetValueFetcherForProperty(This.GetType(), propName);

            return This.Changed
                .Where(x => x.PropertyName == propName)
                .Select(_ => new ObservedChange<TSender, TTarget>() {
                    Sender = This,
                    PropertyName = propName,
                    Value = (TTarget)getter(This),
                })
                .StartWith(new ObservedChange<TSender, TTarget>() { Sender = This, PropertyName = propName, Value = (TTarget)getter(This) })
                .Select(selector);
        }
    }
{'fraction_non_alphanumeric': 0.09472372247611134, 'fraction_numerical': 0.0, 'mean_word_length': 2.5833333333333335, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6741620', 'n_tokens_mistral': 658, 'n_tokens_neox': 646, 'n_words': 144}