Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix some minor WP7 glitches

  • Loading branch information...
commit f66c12e6db9cc1df2735e168281f05ef0e4bd18a 1 parent 193d503
@paulcbetts paulcbetts authored
View
88 ReactiveUI/MemoizingMRUCache.cs
@@ -163,94 +163,6 @@ void Invariants()
Contract.Invariant(cacheEntries.Count <= maxCacheSize);
}
}
-
-#if DOTNETISOLDANDSAD || WP7
- public static class Tuple
- {
- public static Tuple<T1, T2> Create<T1, T2>(T1 val1, T2 val2)
- {
- return new Tuple<T1, T2>(val1, val2);
- }
-
- public static Tuple<T1, T2, T3> Create<T1, T2, T3>(T1 val1, T2 val2, T3 val3)
- {
- return new Tuple<T1, T2, T3>(val1, val2, val3);
- }
- }
-
- public class Tuple<T1, T2>
- {
- public Tuple(T1 item1, T2 item2)
- {
- Item1 = item1;
- Item2 = item2;
- var hash1 = (item1 != null) ? item1.GetHashCode() : 0;
- var hash2 = (item2 != null) ? item2.GetHashCode() : 0;
- hash = hash1 ^ hash2;
- }
- public Tuple() {}
-
- private int hash;
- public T1 Item1 {get; set;}
- public T2 Item2 {get; set;}
-
-
- public override bool Equals(object obj)
- {
- var other = obj as Tuple<T1, T2>;
- if (other == null)
- return false;
-
- bool equals1 = (Item1 != null)? Item1.Equals(other.Item1) : other.Item1 == null;
- bool equals2 = (Item2 != null)? Item2.Equals(other.Item2) : other.Item2 == null;
- return equals1 && equals2;
- }
-
- public override int GetHashCode()
- {
- return hash;
- }
- }
-
- public class Tuple<T1, T2, T3>
- {
- public Tuple(T1 item1, T2 item2, T3 item3)
- {
- Item1 = item1;
- Item2 = item2;
- Item3 = item3;
- var hash1 = (item1 != null) ? item1.GetHashCode() : 0;
- var hash2 = (item2 != null) ? item2.GetHashCode() : 0;
- var hash3 = (item3 != null) ? item3.GetHashCode() : 0;
- hash = hash1 ^ hash2 ^ hash3;
- }
- public Tuple() {}
-
- private int hash;
- public T1 Item1 {get; set;}
- public T2 Item2 {get; set;}
- public T3 Item3 {get; set;}
-
-
- public override bool Equals(object obj)
- {
- var other = obj as Tuple<T1, T2, T3>;
- if (other == null)
- return false;
-
- bool equals1 = (Item1 != null)? Item1.Equals(other.Item1) : other.Item1 == null;
- bool equals2 = (Item2 != null)? Item2.Equals(other.Item2) : other.Item2 == null;
- bool equals3 = (Item3 != null)? Item3.Equals(other.Item3) : other.Item3 == null;
- return equals1 && equals2 && equals3;
- }
-
- public override int GetHashCode()
- {
- return hash;
- }
- }
-
-#endif
}
// vim: tw=120 ts=4 sw=4 et :
View
54 ReactiveUI/VariadicTemplates_WP7.cs
@@ -26,17 +26,20 @@ public static class WhenAnyMixin
Expression<Func<TSender, T1>> property1,
Func<IObservedChange<TSender, T1>, TRet> selector)
{
+ bool allInputsWorked = true;
var slot1 = new ObservedChange<TSender, T1>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property1)),
};
- T1 slot1Value = default(T1); slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
+ T1 slot1Value = default(T1); allInputsWorked &= slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
IObservedChange<TSender, T1> islot1 = slot1;
return Observable.Create<TRet>(subject => {
- subject.OnNext(selector(islot1));
+ if (allInputsWorked) subject.OnNext(selector(islot1));
- return Observable.Merge( This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1)) ).Subscribe(subject);
+ return Observable.Merge(
+ This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1))
+ ).Subscribe(subject);
});
}
@@ -78,23 +81,27 @@ public static class WhenAnyMixin
Expression<Func<TSender, T2>> property2,
Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, TRet> selector)
{
+ bool allInputsWorked = true;
var slot1 = new ObservedChange<TSender, T1>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property1)),
};
- T1 slot1Value = default(T1); slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
+ T1 slot1Value = default(T1); allInputsWorked &= slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
IObservedChange<TSender, T1> islot1 = slot1;
var slot2 = new ObservedChange<TSender, T2>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property2)),
};
- T2 slot2Value = default(T2); slot2.TryGetValue(out slot2Value); slot2.Value = slot2Value;
+ T2 slot2Value = default(T2); allInputsWorked &= slot2.TryGetValue(out slot2Value); slot2.Value = slot2Value;
IObservedChange<TSender, T2> islot2 = slot2;
return Observable.Create<TRet>(subject => {
- subject.OnNext(selector(islot1, islot2));
+ if (allInputsWorked) subject.OnNext(selector(islot1, islot2));
- return Observable.Merge( This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1, islot2)), This.ObservableForProperty(property2).Do(x => { lock (slot2) { islot2 = x.fillInValue(); } }).Select(x => selector(islot1, islot2)) ).Subscribe(subject);
+ return Observable.Merge(
+ This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1, islot2)),
+ This.ObservableForProperty(property2).Do(x => { lock (slot2) { islot2 = x.fillInValue(); } }).Select(x => selector(islot1, islot2))
+ ).Subscribe(subject);
});
}
@@ -144,29 +151,34 @@ public static class WhenAnyMixin
Expression<Func<TSender, T3>> property3,
Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, TRet> selector)
{
+ bool allInputsWorked = true;
var slot1 = new ObservedChange<TSender, T1>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property1)),
};
- T1 slot1Value = default(T1); slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
+ T1 slot1Value = default(T1); allInputsWorked &= slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
IObservedChange<TSender, T1> islot1 = slot1;
var slot2 = new ObservedChange<TSender, T2>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property2)),
};
- T2 slot2Value = default(T2); slot2.TryGetValue(out slot2Value); slot2.Value = slot2Value;
+ T2 slot2Value = default(T2); allInputsWorked &= slot2.TryGetValue(out slot2Value); slot2.Value = slot2Value;
IObservedChange<TSender, T2> islot2 = slot2;
var slot3 = new ObservedChange<TSender, T3>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property3)),
};
- T3 slot3Value = default(T3); slot3.TryGetValue(out slot3Value); slot3.Value = slot3Value;
+ T3 slot3Value = default(T3); allInputsWorked &= slot3.TryGetValue(out slot3Value); slot3.Value = slot3Value;
IObservedChange<TSender, T3> islot3 = slot3;
return Observable.Create<TRet>(subject => {
- subject.OnNext(selector(islot1, islot2, islot3));
+ if (allInputsWorked) subject.OnNext(selector(islot1, islot2, islot3));
- return Observable.Merge( This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3)), This.ObservableForProperty(property2).Do(x => { lock (slot2) { islot2 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3)), This.ObservableForProperty(property3).Do(x => { lock (slot3) { islot3 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3)) ).Subscribe(subject);
+ return Observable.Merge(
+ This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3)),
+ This.ObservableForProperty(property2).Do(x => { lock (slot2) { islot2 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3)),
+ This.ObservableForProperty(property3).Do(x => { lock (slot3) { islot3 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3))
+ ).Subscribe(subject);
});
}
@@ -224,35 +236,41 @@ public static class WhenAnyMixin
Expression<Func<TSender, T4>> property4,
Func<IObservedChange<TSender, T1>, IObservedChange<TSender, T2>, IObservedChange<TSender, T3>, IObservedChange<TSender, T4>, TRet> selector)
{
+ bool allInputsWorked = true;
var slot1 = new ObservedChange<TSender, T1>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property1)),
};
- T1 slot1Value = default(T1); slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
+ T1 slot1Value = default(T1); allInputsWorked &= slot1.TryGetValue(out slot1Value); slot1.Value = slot1Value;
IObservedChange<TSender, T1> islot1 = slot1;
var slot2 = new ObservedChange<TSender, T2>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property2)),
};
- T2 slot2Value = default(T2); slot2.TryGetValue(out slot2Value); slot2.Value = slot2Value;
+ T2 slot2Value = default(T2); allInputsWorked &= slot2.TryGetValue(out slot2Value); slot2.Value = slot2Value;
IObservedChange<TSender, T2> islot2 = slot2;
var slot3 = new ObservedChange<TSender, T3>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property3)),
};
- T3 slot3Value = default(T3); slot3.TryGetValue(out slot3Value); slot3.Value = slot3Value;
+ T3 slot3Value = default(T3); allInputsWorked &= slot3.TryGetValue(out slot3Value); slot3.Value = slot3Value;
IObservedChange<TSender, T3> islot3 = slot3;
var slot4 = new ObservedChange<TSender, T4>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property4)),
};
- T4 slot4Value = default(T4); slot4.TryGetValue(out slot4Value); slot4.Value = slot4Value;
+ T4 slot4Value = default(T4); allInputsWorked &= slot4.TryGetValue(out slot4Value); slot4.Value = slot4Value;
IObservedChange<TSender, T4> islot4 = slot4;
return Observable.Create<TRet>(subject => {
- subject.OnNext(selector(islot1, islot2, islot3, islot4));
+ if (allInputsWorked) subject.OnNext(selector(islot1, islot2, islot3, islot4));
- return Observable.Merge( This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4)), This.ObservableForProperty(property2).Do(x => { lock (slot2) { islot2 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4)), This.ObservableForProperty(property3).Do(x => { lock (slot3) { islot3 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4)), This.ObservableForProperty(property4).Do(x => { lock (slot4) { islot4 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4)) ).Subscribe(subject);
+ return Observable.Merge(
+ This.ObservableForProperty(property1).Do(x => { lock (slot1) { islot1 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4)),
+ This.ObservableForProperty(property2).Do(x => { lock (slot2) { islot2 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4)),
+ This.ObservableForProperty(property3).Do(x => { lock (slot3) { islot3 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4)),
+ This.ObservableForProperty(property4).Do(x => { lock (slot4) { islot4 = x.fillInValue(); } }).Select(x => selector(islot1, islot2, islot3, islot4))
+ ).Subscribe(subject);
});
}
View
7 ReactiveUI/VariadicTemplates_WP7.tt
@@ -44,20 +44,23 @@ namespace ReactiveUI
<# } #>
Func<<#= selectorTypeParams #>, TRet> selector)
{
+ bool allInputsWorked = true;
<# for(int i=1; i <= length; i++) { #>
var slot<#=i#> = new ObservedChange<TSender, T<#=i#>>() {
Sender = This,
PropertyName = String.Join(".", Reflection.ExpressionToPropertyNames(property<#=i#>)),
};
- T<#=i#> slot<#=i#>Value = default(T<#=i#>); slot<#=i#>.TryGetValue(out slot<#=i#>Value); slot<#=i#>.Value = slot<#=i#>Value;
+ T<#=i#> slot<#=i#>Value = default(T<#=i#>); allInputsWorked &= slot<#=i#>.TryGetValue(out slot<#=i#>Value); slot<#=i#>.Value = slot<#=i#>Value;
IObservedChange<TSender, T<#=i#>> islot<#=i#> = slot<#=i#>;
<# } #>
return Observable.Create<TRet>(subject => {
- subject.OnNext(<#= selectorCall #>);
+ if (allInputsWorked) subject.OnNext(<#= selectorCall #>);
return Observable.Merge(<# for(int i=1; i <= length; i++) { #>
+
This.ObservableForProperty(property<#=i#>).Do(x => { lock (slot<#=i#>) { islot<#=i#> = x.fillInValue(); } }).Select(x => <#= selectorCall #>)<#= (i==length?"":",") #> <# } #>
+
).Subscribe(subject);
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.