| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the Apache 2.0 License.
- // See the LICENSE file in the project root for more information.
- using System.Reactive.Concurrency;
- namespace System.Reactive.Linq
- {
- public static partial class Observable
- {
- #region + FromEventPattern +
- #region Strongly typed
- #region Action<EventHandler>
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on <see cref="EventHandler"/>, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<object>> FromEventPattern(Action<EventHandler> addHandler, Action<EventHandler> removeHandler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEventPattern(addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on <see cref="EventHandler"/>, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<object>> FromEventPattern(Action<EventHandler> addHandler, Action<EventHandler> removeHandler, IScheduler scheduler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern(addHandler, removeHandler, scheduler);
- }
- #endregion
- #region Action<TDelegate>
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on a supplied event delegate type, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEventPattern<TDelegate, TEventArgs>(addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on a supplied event delegate type, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern<TDelegate, TEventArgs>(addHandler, removeHandler, scheduler);
- }
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on <see cref="EventHandler{TEventArgs}"/>, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="conversion">A function used to convert the given event handler to a delegate compatible with the underlying .NET event. The resulting delegate is used in calls to the addHandler and removeHandler action parameters.</param>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="conversion"/> or <paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TDelegate, TEventArgs>(Func<EventHandler<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler)
- {
- if (conversion == null)
- {
- throw new ArgumentNullException(nameof(conversion));
- }
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEventPattern(conversion, addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on <see cref="EventHandler{TEventArgs}"/>, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="conversion">A function used to convert the given event handler to a delegate compatible with the underlying .NET event. The resulting delegate is used in calls to the addHandler and removeHandler action parameters.</param>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="conversion"/> or <paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TDelegate, TEventArgs>(Func<EventHandler<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler)
- {
- if (conversion == null)
- {
- throw new ArgumentNullException(nameof(conversion));
- }
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern(conversion, addHandler, removeHandler, scheduler);
- }
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on a supplied event delegate type with a strongly typed sender parameter, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TSender">The type of the sender that raises the event.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TSender, TEventArgs>> FromEventPattern<TDelegate, TSender, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEventPattern<TDelegate, TSender, TEventArgs>(addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on a supplied event delegate type with a strongly typed sender parameter, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TSender">The type of the sender that raises the event.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TSender, TEventArgs>> FromEventPattern<TDelegate, TSender, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern<TDelegate, TSender, TEventArgs>(addHandler, removeHandler, scheduler);
- }
- #endregion
- #region Action<EventHandler<TEventArgs>>
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on <see cref="EventHandler{TEventArgs}"/>, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TEventArgs>(Action<EventHandler<TEventArgs>> addHandler, Action<EventHandler<TEventArgs>> removeHandler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEventPattern(addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a .NET event, conforming to the standard .NET event pattern based on <see cref="EventHandler{TEventArgs}"/>, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TEventArgs>(Action<EventHandler<TEventArgs>> addHandler, Action<EventHandler<TEventArgs>> removeHandler, IScheduler scheduler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern(addHandler, removeHandler, scheduler);
- }
- #endregion
- #endregion
- #region Reflection
- #region Instance events
- /// <summary>
- /// Converts an instance .NET event, conforming to the standard .NET event pattern with an <see cref="EventArgs"/> parameter, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the target object type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <param name="target">Object instance that exposes the event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="target"/> or <paramref name="eventName"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<object>> FromEventPattern(object target, string eventName)
- {
- if (target == null)
- {
- throw new ArgumentNullException(nameof(target));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- return s_impl.FromEventPattern(target, eventName);
- }
- /// <summary>
- /// Converts an instance .NET event, conforming to the standard .NET event pattern with an <see cref="EventArgs"/> parameter, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the target object type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <param name="target">Object instance that exposes the event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="target"/> or <paramref name="eventName"/> or <paramref name="scheduler"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<object>> FromEventPattern(object target, string eventName, IScheduler scheduler)
- {
- if (target == null)
- {
- throw new ArgumentNullException(nameof(target));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern(target, eventName, scheduler);
- }
- /// <summary>
- /// Converts an instance .NET event, conforming to the standard .NET event pattern with strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the target object type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="target">Object instance that exposes the event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="target"/> or <paramref name="eventName"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TEventArgs>(object target, string eventName)
- {
- if (target == null)
- {
- throw new ArgumentNullException(nameof(target));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- return s_impl.FromEventPattern<TEventArgs>(target, eventName);
- }
- /// <summary>
- /// Converts an instance .NET event, conforming to the standard .NET event pattern with strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the target object type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="target">Object instance that exposes the event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="target"/> or <paramref name="eventName"/> or <paramref name="scheduler"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TEventArgs>(object target, string eventName, IScheduler scheduler)
- {
- if (target == null)
- {
- throw new ArgumentNullException(nameof(target));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern<TEventArgs>(target, eventName, scheduler);
- }
- /// <summary>
- /// Converts an instance .NET event, conforming to the standard .NET event pattern with a strongly typed sender and strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the target object type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TSender">The type of the sender that raises the event.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="target">Object instance that exposes the event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="target"/> or <paramref name="eventName"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's first argument type is not assignable to TSender. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TSender, TEventArgs>> FromEventPattern<TSender, TEventArgs>(object target, string eventName)
- {
- if (target == null)
- {
- throw new ArgumentNullException(nameof(target));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- return s_impl.FromEventPattern<TSender, TEventArgs>(target, eventName);
- }
- /// <summary>
- /// Converts an instance .NET event, conforming to the standard .NET event pattern with a strongly typed sender and strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the target object type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TSender">The type of the sender that raises the event.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="target">Object instance that exposes the event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="target"/> or <paramref name="eventName"/> or <paramref name="scheduler"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's first argument type is not assignable to TSender. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TSender, TEventArgs>> FromEventPattern<TSender, TEventArgs>(object target, string eventName, IScheduler scheduler)
- {
- if (target == null)
- {
- throw new ArgumentNullException(nameof(target));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern<TSender, TEventArgs>(target, eventName, scheduler);
- }
- #endregion
- #region Static events
- /// <summary>
- /// Converts a static .NET event, conforming to the standard .NET event pattern with an <see cref="EventArgs"/> parameter, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the specified type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <param name="type">Type that exposes the static event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="eventName"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<object>> FromEventPattern(Type type, string eventName)
- {
- if (type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- return s_impl.FromEventPattern(type, eventName);
- }
- /// <summary>
- /// Converts a static .NET event, conforming to the standard .NET event pattern with an <see cref="EventArgs"/> parameter, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the specified type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <param name="type">Type that exposes the static event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="eventName"/> or <paramref name="scheduler"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<object>> FromEventPattern(Type type, string eventName, IScheduler scheduler)
- {
- if (type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern(type, eventName, scheduler);
- }
- /// <summary>
- /// Converts a static .NET event, conforming to the standard .NET event pattern with strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the specified type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="type">Type that exposes the static event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="eventName"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TEventArgs>(Type type, string eventName)
- {
- if (type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- return s_impl.FromEventPattern<TEventArgs>(type, eventName);
- }
- /// <summary>
- /// Converts a static .NET event, conforming to the standard .NET event pattern with strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the specified type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="type">Type that exposes the static event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="eventName"/> or <paramref name="scheduler"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TEventArgs>> FromEventPattern<TEventArgs>(Type type, string eventName, IScheduler scheduler)
- {
- if (type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern<TEventArgs>(type, eventName, scheduler);
- }
- /// <summary>
- /// Converts a static .NET event, conforming to the standard .NET event pattern with a strongly typed sender and strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the specified type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TSender">The type of the sender that raises the event.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="type">Type that exposes the static event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="eventName"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's first argument type is not assignable to TSender. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEventPattern, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEventPattern, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TSender, TEventArgs>> FromEventPattern<TSender, TEventArgs>(Type type, string eventName)
- {
- if (type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- return s_impl.FromEventPattern<TSender, TEventArgs>(type, eventName);
- }
- /// <summary>
- /// Converts a static .NET event, conforming to the standard .NET event pattern with a strongly typed sender and strongly typed event arguments, to an observable sequence.
- /// Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// Reflection is used to discover the event based on the specified type and the specified event name.
- /// For conversion of events that don't conform to the standard .NET event pattern, use any of the FromEvent overloads instead.
- /// </summary>
- /// <typeparam name="TSender">The type of the sender that raises the event.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="type">Type that exposes the static event to convert.</param>
- /// <param name="eventName">Name of the event to convert.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains data representations of invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="type"/> or <paramref name="eventName"/> or <paramref name="scheduler"/> is null.</exception>
- /// <exception cref="InvalidOperationException">The event could not be found. -or- The event does not conform to the standard .NET event pattern. -or- The event's first argument type is not assignable to TSender. -or- The event's second argument type is not assignable to TEventArgs.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEventPattern calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEventPattern that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEventPattern"/>
- public static IObservable<EventPattern<TSender, TEventArgs>> FromEventPattern<TSender, TEventArgs>(Type type, string eventName, IScheduler scheduler)
- {
- if (type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
- if (eventName == null)
- {
- throw new ArgumentNullException(nameof(eventName));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEventPattern<TSender, TEventArgs>(type, eventName, scheduler);
- }
- #endregion
- #endregion
- #endregion
- #region + FromEvent +
- #region Action<TDelegate>
- /// <summary>
- /// Converts a .NET event to an observable sequence, using a conversion function to obtain the event delegate. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="conversion">A function used to convert the given event handler to a delegate compatible with the underlying .NET event. The resulting delegate is used in calls to the addHandler and removeHandler action parameters.</param>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="conversion"/> or <paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEvent, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Func<Action<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler)
- {
- if (conversion == null)
- {
- throw new ArgumentNullException(nameof(conversion));
- }
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEvent(conversion, addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a .NET event to an observable sequence, using a conversion function to obtain the event delegate. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="conversion">A function used to convert the given event handler to a delegate compatible with the underlying .NET event. The resulting delegate is used in calls to the addHandler and removeHandler action parameters.</param>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="conversion"/> or <paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Func<Action<TEventArgs>, TDelegate> conversion, Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler)
- {
- if (conversion == null)
- {
- throw new ArgumentNullException(nameof(conversion));
- }
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEvent(conversion, addHandler, removeHandler, scheduler);
- }
- /// <summary>
- /// Converts a .NET event to an observable sequence, using a supplied event delegate type. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEvent, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEvent<TDelegate, TEventArgs>(addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a .NET event to an observable sequence, using a supplied event delegate type. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <typeparam name="TDelegate">The delegate type of the event to be converted.</typeparam>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler, IScheduler scheduler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEvent<TDelegate, TEventArgs>(addHandler, removeHandler, scheduler);
- }
- #endregion
- #region Action<Action<TEventArgs>>
- /// <summary>
- /// Converts a generic Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEvent, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<TEventArgs> FromEvent<TEventArgs>(Action<Action<TEventArgs>> addHandler, Action<Action<TEventArgs>> removeHandler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEvent(addHandler, removeHandler);
- }
- /// <summary>
- /// Converts a generic Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <typeparam name="TEventArgs">The type of the event data generated by the event.</typeparam>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<TEventArgs> FromEvent<TEventArgs>(Action<Action<TEventArgs>> addHandler, Action<Action<TEventArgs>> removeHandler, IScheduler scheduler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEvent(addHandler, removeHandler, scheduler);
- }
- #endregion
- #region Action<Action>
- /// <summary>
- /// Converts an Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// The current <see cref="SynchronizationContext"/> is captured during the call to FromEvent, and is used to post add and remove handler invocations.
- /// This behavior ensures add and remove handler operations for thread-affine events are accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// If no SynchronizationContext is present at the point of calling FromEvent, add and remove handler invocations are made synchronously on the thread
- /// making the Subscribe or Dispose call, respectively.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions due to the free-threaded nature of Reactive Extensions. Doing so
- /// makes the captured SynchronizationContext predictable. This best practice also reduces clutter of bridging code inside queries, making the query expressions
- /// more concise and easier to understand.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<Unit> FromEvent(Action<Action> addHandler, Action<Action> removeHandler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- return s_impl.FromEvent(addHandler, removeHandler);
- }
- /// <summary>
- /// Converts an Action-based .NET event to an observable sequence. Each event invocation is surfaced through an OnNext message in the resulting sequence.
- /// For conversion of events conforming to the standard .NET event pattern, use any of the FromEventPattern overloads instead.
- /// </summary>
- /// <param name="addHandler">Action that attaches the given event handler to the underlying .NET event.</param>
- /// <param name="removeHandler">Action that detaches the given event handler from the underlying .NET event.</param>
- /// <param name="scheduler">The scheduler to run the add and remove event handler logic on.</param>
- /// <returns>The observable sequence that contains the event argument objects passed to the invocations of the underlying .NET event.</returns>
- /// <exception cref="ArgumentNullException"><paramref name="addHandler"/> or <paramref name="removeHandler"/> or <paramref name="scheduler"/> is null.</exception>
- /// <remarks>
- /// <para>
- /// Add and remove handler invocations are made whenever the number of observers grows beyond zero.
- /// As such, an event handler may be shared by multiple simultaneously active observers, using a subject for multicasting.
- /// </para>
- /// <para>
- /// Add and remove handler invocations are run on the specified scheduler. This behavior allows add and remove handler operations for thread-affine events to be
- /// accessed from the same context, as required by some UI frameworks.
- /// </para>
- /// <para>
- /// It's recommended to lift FromEvent calls outside event stream query expressions. This best practice reduces clutter of bridging code inside queries,
- /// making the query expressions more concise and easier to understand. This has additional benefits for overloads of FromEvent that omit the IScheduler
- /// parameter. For more information, see the remarks section on those overloads.
- /// </para>
- /// </remarks>
- /// <seealso cref="ToEvent"/>
- public static IObservable<Unit> FromEvent(Action<Action> addHandler, Action<Action> removeHandler, IScheduler scheduler)
- {
- if (addHandler == null)
- {
- throw new ArgumentNullException(nameof(addHandler));
- }
- if (removeHandler == null)
- {
- throw new ArgumentNullException(nameof(removeHandler));
- }
- if (scheduler == null)
- {
- throw new ArgumentNullException(nameof(scheduler));
- }
- return s_impl.FromEvent(addHandler, removeHandler, scheduler);
- }
- #endregion
- #endregion
- }
- }
|