1

我正在尝试从以下事件创建一个 IObservable:

public delegate bool Handle<in T>(T obj, Foo foo);

 event Handle<Bar> Finance;

关于如何正确创建可观察对象的任何建议?

注意,Foo 和 Bar 都不是基于 EventArgs

谢谢!

4

1 回答 1

2

您可以尝试以下方法:

public class Test
{
    public delegate void Handle<in T>(T obj, Foo foo);

    public event Handle<Bar> Finance;
}

public static class TestEx
{
    static IObservable<Tuple<Bar, Foo>> WhenFinanceChanged(this Test t)
    {
        return Observable.Create<Tuple<Bar, Foo>>(observer =>
        {
            Test.Handle<Bar> handler = (obj, foo) => observer.OnNext(Tuple.Create<Bar, Foo>(obj, foo));
            t.Finance += handler;
            return Disposable.Create(() => t.Finance -= handler);
        });
    }
}
于 2012-12-19T17:44:45.733 回答