| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="SubscriberLists.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | |
| | | 9 | | namespace MyNet.Utilities.Execution; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Helper for managing lists of items associated to subscribers (e.g. for tracking subscriptions of a subscriber to mul |
| | | 13 | | /// </summary> |
| | | 14 | | internal static class SubscriberLists |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Adds an item to the list associated to the specified subscriber in the dictionary, creating a new list if the su |
| | | 18 | | /// </summary> |
| | | 19 | | /// <param name="dictionary">The dictionary mapping subscribers to their lists of items.</param> |
| | | 20 | | /// <param name="subscriber">The subscriber for whom the item is being added.</param> |
| | | 21 | | /// <param name="item">The item to add to the subscriber's list.</param> |
| | | 22 | | /// <typeparam name="T">The type of items in the list.</typeparam> |
| | | 23 | | public static void Add<T>(Dictionary<object, List<T>> dictionary, object subscriber, T item) |
| | | 24 | | { |
| | 15 | 25 | | if (!dictionary.TryGetValue(subscriber, out var list)) |
| | | 26 | | { |
| | 15 | 27 | | list = []; |
| | 15 | 28 | | dictionary[subscriber] = list; |
| | | 29 | | } |
| | | 30 | | |
| | 15 | 31 | | list.Add(item); |
| | 15 | 32 | | } |
| | | 33 | | } |
| | | 34 | | |