Incorrect method used and further specification

This commit is contained in:
Timothy Schenk 2022-12-29 12:10:57 +01:00
parent 24abacdb8d
commit 14138d1c4c

View file

@ -17,7 +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().IsAssignableFrom(typeof(IPacket)))
.Where(x => x.attr != null && x.ctor != null && x.GetType().IsAssignableTo(typeof(IPacket)) &&
x.GetType().IsClass)
.ToImmutableDictionary(x => x.attr!.PacketId, x => x.ctor)!;
}