Skip to content

ReadOnlyReactiveProperty<T>.ToReadOnlyReactiveProperty() has dangerously different (disposability) behavior from ReactivePropertyExtensions.ToReadOnlyReactiveProperty() #393

Description

@wizardness

Strongly related to #263
Reproduced on R3 1.3.0 (.NET 10)

The case that bit me (no shade, I love this library):

var rp = new ReactiveProperty<int>(1);
var view = rp.ToReadOnlyReactiveProperty(); // instance method returns self
view.Dispose();
rp.Value = 5;        // throws ObjectDisposedException

More generally, code that looks the same requires different disposal handling:

var rp = new ReactiveProperty<int>(1);
ReadOnlyReactiveProperty<int> asReadOnly = rp;   // cast, same object
Observable<int> asObservable = rp;               // cast, same object

ReferenceEquals(rp, rp.ToReadOnlyReactiveProperty());            // True   - instance method
ReferenceEquals(rp, asReadOnly.ToReadOnlyReactiveProperty());    // True   - instance method
ReferenceEquals(rp, asObservable.ToReadOnlyReactiveProperty());  // False  - extension method

Passing an argument also flips which method is called:

ReferenceEquals(rp, rp.ToReadOnlyReactiveProperty());     // True  - instance method (no params)
ReferenceEquals(rp, rp.ToReadOnlyReactiveProperty(99));   // False - extension method (one param)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions