[英]Type problem with Observable.Create from Boo
I'm trying to use Reactive Extensions from Boo and am running into type problems. 我正在尝试使用Boo的Reactive Extensions,并且遇到类型问题。 Here's the basic example:
这是基本示例:
def OnSubscribe(observer as IObservable[of string]) as callable:
print "subscribing"
def Dispose():
print "disposing"
return Dispose
observable = System.Linq.Observable.Create[of string](OnSubscribe)
observer = System.Linq.Observer.Create[of string]({x as string | print x})
observable.Subscribe(observer)
The Subscribe here gives a System.InvalidCastException: Cannot cast from source type to destination type. 此处的订阅给出System.InvalidCastException:无法从源类型转换为目标类型。 The issue appears to be with how I'm creating the observable, but I've struggled to see where the type problem arises from.
问题似乎与如何创建可观察对象有关,但是我一直在努力寻找类型问题的来源。
Ideas? 有想法吗?
Observable.Create
takes Func<IObserver,Action>
, but your OnSubscribe
accepts an IObservable
. Observable.Create
接受Func<IObserver,Action>
,但是您的OnSubscribe
接受IObservable
。
Try this: 尝试这个:
def OnSubscribe(observer as IObserver[of string]) as callable():
print "subscribing"
observer.OnNext("first and only value")
observer.OnCompleted()
def Dispose():
print "disposing"
return Dispose
observable = System.Linq.Observable.Create[of string](OnSubscribe)
observer = System.Linq.Observer.Create[of string]({x as string | print x})
observable.Subscribe(observer)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.