反应式扩展 - 新版本中旧版本使用方法的问题

发布于 2024-11-14 20:40:57 字数 1641 浏览 1 评论 0原文

我是 .NET 的新手,我之前的工作是 PLC 程序员。我有一个旧应用程序,其中使用了 .NET 的响应式扩展。

我维护这个应用程序的时间不长。现在我下载了反应式扩展的新版本,但使用旧代码时遇到问题。

我知道 Rx 中的某些部分已更改。

这是一个问题旧代码:

    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);

我得到了这个例外:

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 am newbie in .NET my previous job was PLC programmer. I have old application in which I used Reactive Extension for .NET.

I don’t maintain this app a long time. Now I downloaded new version for Reactive Extension but I have problem with using old code.

I know that some parts in Rx was changed.

Here is a problem 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 this 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 don’t know which method I must use in new version for same funcionality.

Thank for advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

简单爱 2024-11-21 20:40:57

在最新版本(1.1.10425.0)中,需要使用FromEventPattern()

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

白昼 2024-11-21 20:40:57

官方 Rx 论坛在此发布 http://social.msdn.microsoft.com/Forums/en-US/rx/thread/527002a3-18af-4eda-8e35-760ca0006b98 有一篇关于更改的文章他们在 1.1.10425.0 中制作。 Lee Campbell 在 http 上写了一篇很好的文章,介绍了其中一些更改的影响://leecampbell.blogspot.com/2011/06/rx-v1010425writing-changes.html。我在 http: //www.thinqlinq.com/Post.aspx/Title/Updating-Reactive-Samples-to-10425-build 以及。

在您的例子中,您使用的是 FromEvent 方法和事件名称的字符串。此签名已移至 FromEventPattern。您可以进行全局搜索并替换 FromEvent( 并将其更改为 FromEventPattern( ,不会有太多问题。

此外,您似乎在本示例中调用了 LoadUser 两次(在 Do 中,然后在 Subscribe 中再次调用)。您可能想要当然你需要这样做两次。

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

In your case, you're using the FromEvent method with the string of the event name. This signature was moved to FromEventPattern. You can probably do a global search and replace on FromEvent( and change it to FromEventPattern( without having much problems.

Additionally, you appear to be calling LoadUser twice in this example (in Do and then again in Subscribe). You may want to make sure you need to do that twice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文