Refactor where clause

This commit is contained in:
Timothy Schenk 2022-12-29 13:54:17 +01:00
parent 5d493c7001
commit 95e5e35b6a

View file

@ -17,8 +17,8 @@ public class PacketForwardingService
// Get all types that implement IPacket and have a PacketIdAttribute
_packets = assembly.GetTypes()
.Select(x => (attr: x.GetCustomAttribute<PacketIdAttribute>(), ctor: x.GetConstructor(Type.EmptyTypes)))
.Where(x => x.attr != null && x.ctor != null && x.GetType().IsAssignableTo(typeof(IPacket)) &&
x.GetType().IsClass)
.Where(x => x.GetType().IsAssignableTo(typeof(IPacket)) && x.GetType().IsClass)
.Where(x => x.attr != null && x.ctor != null)
.ToImmutableDictionary(x => x.attr!.PacketId, x => x.ctor)!;
}