// // RegisteredMovers.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Reflection; using Microsoft.Extensions.Options; using NosSmooth.Packets; using NosSmooth.PacketSerializer.Abstractions.Attributes; namespace Anonymizer.Movers; /// /// A class containing all of the registered movers, /// initialized as /// by the service extension methods. Used inside of /// . /// public class RegisteredMovers { private readonly HashSet _packetHeaders; /// /// Initializes a new instance of the class. /// public RegisteredMovers() { _packetHeaders = new HashSet(); } /// /// Add the given mover packet type. /// /// The packet to add. public void AddMover() where TPacket : IPacket { var headers = typeof(TPacket).GetCustomAttributes(); foreach (var header in headers) { if (header.Identifier is not null) { _packetHeaders.Add(header.Identifier); } } } /// /// Checks whether the given packet header has a mover registered. /// /// The packet header. /// Whether to try to move the packet. public bool ShouldMove(string packetHeader) { return _packetHeaders.Contains(packetHeader); } }