| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ImmediateCollectionEventDispatcher.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | |
| | | 9 | | namespace MyNet.Collections; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Dispatches events immediately on the current thread. |
| | | 13 | | /// </summary> |
| | | 14 | | public sealed class ImmediateCollectionEventDispatcher : ICollectionEventDispatcher |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets the singleton instance. |
| | | 18 | | /// </summary> |
| | 3 | 19 | | public static ImmediateCollectionEventDispatcher Default { get; } = new(); |
| | | 20 | | |
| | 3 | 21 | | private ImmediateCollectionEventDispatcher() { } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Always returns true since this dispatcher executes actions immediately on the current thread, meaning it always |
| | | 25 | | /// </summary> |
| | | 26 | | /// <returns>True, indicating that the current thread has access to the dispatcher.</returns> |
| | 21 | 27 | | public bool CheckAccess() => true; |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | | 30 | | public void Dispatch(Action action) |
| | | 31 | | { |
| | 3 | 32 | | ArgumentNullException.ThrowIfNull(action); |
| | 3 | 33 | | action(); |
| | 3 | 34 | | } |
| | | 35 | | } |
| | | 36 | | |