可观察的<>缺少 .Subscribe 扩展方法 [英] IObservable<> missing .Subscribe extension methods

查看:15
本文介绍了可观察的<>缺少 .Subscribe 扩展方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RX 扩展和 WF4 创建一个工作流,该工作流对可观察到的消息做出反应以推进工作流.为此,我引入了一个包含 IObservable 的对象(ModuleMessage 是我的抽象类).我遇到的问题是 .Subscribe 无法识别其任何扩展方法,即用于 lambda 扩展/方法组的扩展方法.在下面的代码中,我有引用:

I'm using RX extensions and WF4 to create a workflow which reacts to observable messages to progress the workflow. To do this, I bring in an object containing an IObservable (ModuleMessage being my abstract class.) The problem I'm having is that .Subscribe fails to recognize any of its extension methods, namely the one for lambda extpressions/method groups. In the following code, I have references:

using System.Activities;
using System.Activities.Hosting;
using System.Collections.Generic;
using System.Reactive.Linq;

还有下面这行代码:

    internal void AddModuleCallback(IModule module)
    {
        if (!addedCallback)
        {
            addedCallback = true;
            module.Messages.Where(m => m is MemberLeftModuleMessage || m is MemberRemovedModuleMessage).Subscribe(m => this.OnMemberExit(m)); // This line errors
        }
    }

    internal void OnMemberExit(ModuleMessage message)
    {
        // Gizmo was fired, resume the bookmark
        this.instance.BeginResumeBookmark(
            new Bookmark(ModuleVisit.BookmarkName),
            message is MemberLeftModuleMessage,
            r => this.instance.EndResumeBookmark(r),
            null);
    }

编译时错误:

Error   1   Cannot convert lambda expression to type 'System.IObserver<Components.Messages.ModuleMessage>' because it is not a delegate type    <Removed>WaitForModuleVisitExtension.cs    34  119 Components

请注意,此代码改编自一个示例,并没有按照我的喜好进行分解,我只是关心手头的问题.我不是 RX 或 WF4 的专业人士,但在同一解决方案的其他地方以这种方式使用了订阅.我已经通过 NuGet 将 RX 添加到这个项目中.

Please note, this code is adapted from a sample and has not been factored out to my liking, I'm purely concerned in the problem at hand. I'm no pro with RX or WF4, but have used subscribe in this way elsewhere in the very same solution. I've added RX to this project via NuGet.

如果我用作方法组(而不是 lambda),则会出现以下错误:

the following error if I use as a method group (instead of lambda):

Error   2   Argument 1: cannot convert from 'method group' to 'System.IObserver<Components.Messages.ModuleMessage>' <removed>WaitForModuleVisitExtension.cs    34  119 Components

推荐答案

你错过了这个:

using System;

这是包含 ObservableExtensions 具有所有 Subscribe 扩展方法的静态类.

That's the namespace containing the ObservableExtensions static class with all the Subscribe extension methods.

通过 using 指令(以及尝试使用它们的代码的命名空间层次结构)发现"扩展方法.

Extension methods are "discovered" via using directives (as well as the namespace hierarchy of the code trying to use them).

这篇关于可观察的&lt;&gt;缺少 .Subscribe 扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆