Reactive Extension - method of using the problem from the old version to the new version

I am new to .NET. My previous job was a PLC programmer. I have an old application in which I used the Reactive Extension for .NET.

I do not support this application for a long time. Now I have downloaded the new version for the Reactive Extension, but I have a problem using the old code.

I know some parts in Rx have been changed.

Here is the problem of the old code:

Observable.FromEvent<PropertyChangedEventArgs>(this, "PropertyChanged") .Where(e => e.EventArgs.PropertyName == "Nick") .Select(_ => this.Nick) .Where(text => text.Length > 3) .Do(LoadUser) .Throttle(TimeSpan.FromSeconds(3000)) .Subscribe(LoadUser); 

I got the following exceptions:

 Error 3 Argument 1: cannot convert from 'Spirit.ViewModels.AddFriendViewModel' to 'System.Action<System.Action<System.ComponentModel.PropertyChangedEventArgs>>' E:\C#_Projects\Pokec_Messenger\Spirit_Caliburn_Micro_v1.0\ViewModels\AddFriendViewModel.cs 123 60 Spirit_Caliburn_Micro_v1.0 Error 4 Argument 2: cannot convert from 'string' to 'System.Action<System.Action<System.ComponentModel.PropertyChangedEventArgs>>' E:\C#_Projects\Pokec_Messenger\Spirit_Caliburn_Micro_v1.0\ViewModels\AddFriendViewModel.cs 123 65 Spirit_Caliburn_Micro_v1.0 Error 2 The best overloaded method match for 'System.Reactive.Linq.Observable.FromEvent<System.ComponentModel.PropertyChangedEventArgs>(System.Action<System.Action<System.ComponentModel.PropertyChangedEventArgs>>, System.Action<System.Action<System.ComponentModel.PropertyChangedEventArgs>>)' has some invalid arguments E:\C#_Projects\Pokec_Messenger\Spirit_Caliburn_Micro_v1.0\ViewModels\AddFriendViewModel.cs 123 13 Spirit_Caliburn_Micro_v1.0 

I do not know which method I should use in the new version for the same functionality.

Thanks for the advice.

+6
source share
2 answers

In the latest version (1.1.10425.0) you need to use FromEventPattern()

+7
source

The official Rx Forums forum here http://social.msdn.microsoft.com/Forums/en-US/rx/thread/527002a3-18af-4eda-8e35-760ca0006b98 contains information about the changes they made in 1.1.10425.0. Lee Campbell wrote well about the impact of some of these changes on http://leecampbell.blogspot.com/2011/06/rx-v1010425breaking-changes.html . I shared my experience updating old samples at http://www.thinqlinq.com/Post.aspx/Title/Updating-Reactive-Samples-to-10425-build .

In your case, you use the FromEvent method with an event name string. This signature has been ported to FromEventPattern. Perhaps you can do a global search and replace it with FromEvent (and change it to FromEventPattern (without much trouble).

Also, you seem to call LoadUser twice in this example (in Do, and then again in Subscribe). You may want to make sure you need to do this twice.

+3
source

Source: https://habr.com/ru/post/890161/


All Articles