简体   繁体   中英

Observable.fromEventPattern TypedEventHandler

I am able to generate an Observable from HID Input Report events, but I would like to dive in to the packet data with Linq queries.

I am having trouble making all the types line up.

readerPackets = Observable
    .FromEventPattern
        <TypedEventHandler<HidDevice, HidInputReportReceivedEventArgs>,
        HidDevice,
        HidInputReportReceivedEventArgs>(
            h => reader.InputReportReceived += h,
            h => reader.InputReportReceived -= h)
    .Select(x => x.EventArgs);

This works without the .Select. When I add the select I get the error:

Cannot implicitly convert type 'System.IObservable<Windows.Devices.HumanInterfaceDevice.HidInputReportReceivedEventArgs>' to 'System.IObservable<System.Reactive.EventPattern<Windows.Devices.HumanInterfaceDevice.HidDevice,Windows.Devices.HumanInterfaceDevice.HidInputReportReceivedEventArgs>>'. An explicit conversion exists (are you missing a cast?)

I have tried casting with the types listed in the error, but apparently I am missing something because I can never make it happy.

Can you tell what cast type I should use and where it should be placed?

I found the problem. The compiler highlights the select line as the error. The real error was the type of "readerPackets". By adjusting that type I was able to make the code functional.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM