Skip to content

Observable.Cast<T> #1

@cwharris

Description

@cwharris

Hello! I would expect the following code to be valid.

var source = Observable.Empty<BaseClass>();
var destination = source
    .Where(x => x is DerivedClass)
    .Cast<DerivedClass>();

However, Cast takes an IObservable<object>, and therefore the types are not compatible. Calling the method directly doesn't work either...

var source = Observable.Empty<BaseClass>();
var filtered = source
    .Where(x => x is DerivedClass);
var destination = Observable.Cast<DerivedClass>(filtered);

In both cases, the following compilation error is produced.

Argument 1: cannot convert from 'System.IObservable<T>' to 'System.IObservable<object>'

Is there a reason to avoid doing something like this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions