Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bd5292a

Browse files
authoredJan 26, 2021
Merge pull request #227 from runceel/main
v7.7
2 parents 2340d86 + d6377b2 commit bd5292a

File tree

7 files changed

+67
-3
lines changed

7 files changed

+67
-3
lines changed
 

‎README.md

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ It's very simple.
129129

130130
ReactiveProperty doesn't provide base class by ViewModel, which means that ReactiveProperty can be used together with another MVVM library like Prism, MVVMLight, etc...
131131

132+
## Help support ReactiveProperty
133+
134+
|Name|GitHub Sponsors|
135+
|----|----|
136+
|runceel|https://github.com/sponsors/runceel|
137+
132138
## Documentation
133139

134140
[ReactiveProperty documentation](https://runceel.github.io/ReactiveProperty/)

‎Source/ReactiveProperty.Core/ReactivePropertyMode.cs

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public enum ReactivePropertyMode
2828
/// </summary>
2929
IgnoreInitialValidationError = 0x04,
3030

31+
/// <summary>
32+
/// Ignore exception
33+
/// </summary>
34+
IgnoreException = 0x08,
35+
3136
/// <summary>
3237
/// Default mode value. It is same as DistinctUntilChanged | RaiseLatestValueOnSubscribe.
3338
/// </summary>

‎Source/ReactiveProperty.Core/ReactivePropertySlim.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.ComponentModel;
5+
using System.Runtime.ExceptionServices;
56
using System.Threading;
67
using Reactive.Bindings.Internals;
78

@@ -295,6 +296,8 @@ public T Value
295296

296297
private bool IsRaiseLatestValueOnSubscribe => (_mode & ReactivePropertyMode.RaiseLatestValueOnSubscribe) == ReactivePropertyMode.RaiseLatestValueOnSubscribe;
297298

299+
private bool IsIgnoreException => (_mode & ReactivePropertyMode.IgnoreException) == ReactivePropertyMode.IgnoreException;
300+
298301
/// <summary>
299302
/// Initializes a new instance of the <see cref="ReadOnlyReactivePropertySlim{T}"/> class.
300303
/// </summary>
@@ -427,7 +430,8 @@ void IObserver<T>.OnNext(T value)
427430

428431
void IObserver<T>.OnError(Exception error)
429432
{
430-
// do nothing.
433+
if (IsIgnoreException) return;
434+
ExceptionDispatchInfo.Capture(error).Throw();
431435
}
432436

433437
void IObserver<T>.OnCompleted()

‎Source/ReactiveProperty.NETStandard/ReadOnlyReactiveProperty.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.ComponentModel;
44
using System.Reactive.Concurrency;
55
using System.Reactive.Disposables;
6+
using System.Reactive.PlatformServices;
7+
using System.Runtime.ExceptionServices;
68
using Reactive.Bindings.Internals;
79

810
namespace Reactive.Bindings
@@ -31,6 +33,7 @@ public class ReadOnlyReactiveProperty<T> : IReadOnlyReactiveProperty<T>, IObserv
3133

3234
private bool IsRaiseLatestValueOnSubscribe => (_mode & ReactivePropertyMode.RaiseLatestValueOnSubscribe) == ReactivePropertyMode.RaiseLatestValueOnSubscribe;
3335
private bool IsDistinctUntilChanged => (_mode & ReactivePropertyMode.DistinctUntilChanged) == ReactivePropertyMode.DistinctUntilChanged;
36+
private bool IsIgnoreException => (_mode & ReactivePropertyMode.IgnoreException) == ReactivePropertyMode.IgnoreException;
3437

3538
/// <summary>
3639
/// Initializes a new instance of the <see cref="ReadOnlyReactiveProperty{T}"/> class.
@@ -66,6 +69,10 @@ public ReadOnlyReactiveProperty(
6669

6770
object IReadOnlyReactiveProperty.Value => Value;
6871

72+
/// <summary>
73+
/// Gets a value indicating whether this instance is disposed.
74+
/// </summary>
75+
/// <value><c>true</c> if this instance is disposed; otherwise, <c>false</c>.</value>
6976
public bool IsDisposed => (int)_mode == IsDisposedFlagNumber;
7077

7178
/// <summary>
@@ -181,7 +188,8 @@ void IObserver<T>.OnNext(T value)
181188

182189
void IObserver<T>.OnError(Exception error)
183190
{
184-
// do nothing.
191+
if (IsIgnoreException) return;
192+
ExceptionDispatchInfo.Capture(error).Throw();
185193
}
186194

187195
void IObserver<T>.OnCompleted()

‎Source/SharedProperties.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<RootNamespace>Reactive.Bindings</RootNamespace>
4-
<Version>7.6.1</Version>
4+
<Version>7.7.0</Version>
55
<Authors>neuecc xin9le okazuki</Authors>
66
<PackageProjectUrl>https://github.com/runceel/ReactiveProperty</PackageProjectUrl>
77
<PackageTags>rx mvvm async rx-main reactive</PackageTags>

‎Test/ReactiveProperty.NETStandard.Tests/ReadOnlyReactivePropertySlimTest.cs

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reactive;
45
using System.Reactive.Disposables;
56
using System.Reactive.Linq;
67
using System.Reactive.Subjects;
@@ -199,5 +200,24 @@ public void CreateFromObservableThatCompleteImmediately()
199200
var x = Observable.Return(1).ToReadOnlyReactivePropertySlim();
200201
x.Value.Is(1);
201202
}
203+
204+
[TestMethod]
205+
public void ExceptionThrowsInConvertionLogic()
206+
{
207+
Assert.ThrowsException<Exception>(() =>
208+
_ = Observable.Return(Unit.Default)
209+
.Do(_ => throw new Exception("test"))
210+
.ToReadOnlyReactivePropertySlim(),
211+
"test");
212+
}
213+
214+
[TestMethod]
215+
public void ExceptionThrowsInConvertionLogicWithIgnoreExceptionFlag()
216+
{
217+
AssertEx.DoesNotThrow(() =>
218+
_ = Observable.Return(Unit.Default)
219+
.Do(_ => throw new Exception("test"))
220+
.ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.Default | ReactivePropertyMode.IgnoreException));
221+
}
202222
}
203223
}

‎Test/ReactiveProperty.NETStandard.Tests/ReadOnlyReactivePropertyTest.cs

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reactive;
45
using System.Reactive.Concurrency;
56
using System.Reactive.Disposables;
67
using System.Reactive.Linq;
@@ -190,5 +191,25 @@ public void CreateFromCompletedObservableTest()
190191
recorder.Messages.Count.Is(1);
191192
recorder.Messages.Is(OnCompleted<string>(0));
192193
}
194+
195+
[TestMethod]
196+
public void ExceptionThrowsInConvertionLogic()
197+
{
198+
Assert.ThrowsException<Exception>(() =>
199+
_ = Observable.Return(Unit.Default)
200+
.Do(_ => throw new Exception("test"))
201+
.ToReadOnlyReactiveProperty(),
202+
"test");
203+
}
204+
205+
[TestMethod]
206+
public void ExceptionThrowsInConvertionLogicWithIgnoreExceptionFlag()
207+
{
208+
AssertEx.DoesNotThrow(() =>
209+
_ = Observable.Return(Unit.Default)
210+
.Do(_ => throw new Exception("test"))
211+
.ToReadOnlyReactiveProperty(mode: ReactivePropertyMode.Default | ReactivePropertyMode.IgnoreException));
212+
}
213+
193214
}
194215
}

0 commit comments

Comments
 (0)
Please sign in to comment.