private void TrySubscribeEnumerable(object obj) { var enumerable = obj as IEnumerable; if (enumerable == null) { var observable = Observable2.Coerce <object>(obj); if (observable == null) { SetScalarValue(obj); } else { var collection = new ObservableCollection <object>(); SetScalarValue(collection); source = observable; listSource = collection; subscribing = Dispatcher.CurrentDispatcher.BeginInvoke((Action)SubscribeCollection, DispatcherPriority.DataBind); } } else { listSource = enumerable; var dispatcher = Dispatcher.CurrentDispatcher; var notifier = new DispatchChangesEnumerable(dispatcher, DispatcherPriority.DataBind, enumerable); SetScalarValue(notifier); var notifyingSource = obj as INotifyCollectionChanged; if (notifyingSource != null) { NotifyCollectionChangedEventHandler handler = (sender, e) => notifier.OnCollectionChanged(e); notifyingSource.CollectionChanged += handler; subscription.Disposable = Disposable.Create(() => notifyingSource.CollectionChanged -= handler); } else { var observable = Observable2.Coerce <object>(obj); if (observable != null) { source = observable; subscribing = dispatcher.BeginInvoke((Action <DispatchChangesEnumerable>)SubscribeNotify, DispatcherPriority.DataBind, notifier); } } } }
private void TrySubscribe(object obj) { var observable = Observable2.Coerce <object>(obj); if (observable == null) { SetScalarValue(obj); } else { source = observable; currentValue = null; hasValue = false; subscribing = Dispatcher.CurrentDispatcher.BeginInvoke((Action)Subscribe, DispatcherPriority.DataBind); } }