8

I am working my way through the Hands-On-Labs for reactive extensions (Rx HOL .NET.pdf) which I downloaded from the data developer center (here) a few days ago.

I added these references to my project, using NuGet:

System.Reactive 1.0.10621.0

System.Reactive.Windows.Forms 1.0.10621.0

I'm almost done with the labs, but I've hit a snag trying to implement the .Switch() example, Visual Studio can't locate the extension method:

'System.IObservable' does not contain a definition for 'Switch' and no extension method 'Switch' accepting a first argument of type 'System.IObservable' could be found (are you missing a using directive or an assembly reference?)

Now I know this Hands On Labs document is out of date, because certain things have been renamed (FromEvent became FromEventPattern) and certain things were removed (RemoveTimeStamp) and this document does not reflect that. For the life of me I cannot guess what they renamed Switch to be, or figure out what assembly they might have moved it to, or find a comprehensive list of release notes that indicate it was removed.

Anyone know where I can find Switch and what it's current name is?

Jim Counts
  • 12,535
  • 9
  • 45
  • 63
  • 2
    Thank you for providing a link to the Hand-On-Labs PDF. – Jake Berger Feb 08 '13 at 19:29
  • Just so you know, FromEventPattern is not a renaming of FromEvent. FromEvent is still very much alive. Here is a great explanation of the difference between them - https://stackoverflow.com/a/19896246/540156 – onefootswill Nov 25 '17 at 01:06

1 Answers1

13

The Switch extension method doesn't extend IObservable<T> - it extends IObservable<IObservable<T>>. The full signature is:

IObservable<TSource> Switch<TSource>(this IObservable<IObservable<TSource>> sources)

Try typing Observable.Empty<IObservable<object>>(). and see if Switch appears then.

If not, check your using namespace declarations.

Enigmativity
  • 113,464
  • 11
  • 89
  • 172
  • Thanks. The original example was a `SelectMany` -> `TakeUntil`, I didn't notice that they had changed `from x in foo from y in bar(x)` to `from x in foo select bar(x)`, after using the second form, Switch appeared. – Jim Counts Jul 04 '11 at 16:24
  • 2
    Yep - you usually use Switch after a Select, just like how SelectMany is really just Merge after a Select – Ana Betts Jul 05 '11 at 17:08