forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPOCOObservableForProperty.cs
More file actions
36 lines (33 loc) · 1.4 KB
/
POCOObservableForProperty.cs
File metadata and controls
36 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reactive.Linq;
using Splat;
namespace ReactiveUI
{
/// <summary>
/// This class is the final fallback for WhenAny, and will simply immediately
/// return the value of the type at the time it was created. It will also
/// warn the user that this is probably not what they want to do
/// </summary>
public class POCOObservableForProperty : ICreatesObservableForProperty
{
public int GetAffinityForObject(Type type, string propertyName, bool beforeChanged = false)
{
return 1;
}
static readonly Dictionary<Type, bool> hasWarned = new Dictionary<Type, bool>();
public IObservable<IObservedChange<object, object>> GetNotificationForProperty(object sender, Expression expression, bool beforeChanged = false)
{
var type = sender.GetType();
if (!hasWarned.ContainsKey(type)) {
this.Log().Warn(
"{0} is a POCO type and won't send change notifications, WhenAny will only return a single value!",
type.FullName);
hasWarned[type] = true;
}
return Observable.Return(new ObservedChange<object, object>(sender, expression), RxApp.MainThreadScheduler)
.Concat(Observable.Never<IObservedChange<object, object>>());
}
}
}