如何调试system.reactive的FromEvent函数中的Action M?
How to debug the Action M in FromEvent function of system.reactive?
我正在阅读Captura的源代码,发现action M的调试有点困难(或者我没理解reactive):
FromEvent 是将 c# 事件 (AudioSource.DevicesUpdated) 包装成一个可观察的序列。
包含底层 .NET 事件调用数据表示的 Observable 序列。
readonly IObservable<Unit> _refreshObservable;
_refreshObservable = Observable.FromEvent(M => AudioSource.DevicesUpdated += M,
M => AudioSource.DevicesUpdated -= M)
.Throttle(TimeSpan.FromSeconds(0.5));
_refreshObservable
.ObserveOnUIDispatcher()
.Subscribe(M => Refresh());
public event Action DevicesUpdated;
但是Action“M”的定义在哪里,如何调试呢?谢谢!
M
是您作为参数传递给 FromEvent
operator. This argument is supplied by the Rx. You supply the lambda, and the Rx invokes your lambda with an argument M
that creates internally. This argument represents a handler that your lambda should attach to an event
委托的 conversion
lambda 的参数,所有这一切的发生是因为 C# 语言对您的内容施加了严格的限制可以使用 event
委托(您只能对其应用 +=
和 -=
运算符)。为该参数选择的名称通常是 h
(来自 handler),而不是 M
.
调试 observable 的一种简单方法是使用 Do
运算符对其进行调试,如下所示:
_refreshObservable = Observable
.FromEvent(h => AudioSource.DevicesUpdated += h, h => AudioSource.DevicesUpdated -= h)
.Do(x => Console.WriteLine($"DevicesUpdated original: {x}"))
.Throttle(TimeSpan.FromSeconds(0.5))
.Do(x => Console.WriteLine($"DevicesUpdated throttled: {x}"));
我正在阅读Captura的源代码,发现action M的调试有点困难(或者我没理解reactive):
FromEvent 是将 c# 事件 (AudioSource.DevicesUpdated) 包装成一个可观察的序列。
包含底层 .NET 事件调用数据表示的 Observable 序列。
readonly IObservable<Unit> _refreshObservable;
_refreshObservable = Observable.FromEvent(M => AudioSource.DevicesUpdated += M,
M => AudioSource.DevicesUpdated -= M)
.Throttle(TimeSpan.FromSeconds(0.5));
_refreshObservable
.ObserveOnUIDispatcher()
.Subscribe(M => Refresh());
public event Action DevicesUpdated;
但是Action“M”的定义在哪里,如何调试呢?谢谢!
M
是您作为参数传递给 FromEvent
operator. This argument is supplied by the Rx. You supply the lambda, and the Rx invokes your lambda with an argument M
that creates internally. This argument represents a handler that your lambda should attach to an event
委托的 conversion
lambda 的参数,所有这一切的发生是因为 C# 语言对您的内容施加了严格的限制可以使用 event
委托(您只能对其应用 +=
和 -=
运算符)。为该参数选择的名称通常是 h
(来自 handler),而不是 M
.
调试 observable 的一种简单方法是使用 Do
运算符对其进行调试,如下所示:
_refreshObservable = Observable
.FromEvent(h => AudioSource.DevicesUpdated += h, h => AudioSource.DevicesUpdated -= h)
.Do(x => Console.WriteLine($"DevicesUpdated original: {x}"))
.Throttle(TimeSpan.FromSeconds(0.5))
.Do(x => Console.WriteLine($"DevicesUpdated throttled: {x}"));