- Ignore generic types when find derived types as they cannot be instantiated

This commit is contained in:
littlebotgames 2021-01-26 21:15:59 +00:00
parent 37714bc260
commit 6d0d3d2f3b

View File

@ -50,6 +50,9 @@ public static class ManagedReferenceUtility
continue; continue;
// Skip abstract classes because they should not be instantiated // Skip abstract classes because they should not be instantiated
if (type.IsAbstract) if (type.IsAbstract)
continue;
// Skip generic classes because they can not be instantiated
if (type.ContainsGenericParameters)
continue; continue;
// Skip types that has no public empty constructors (activator can not create them) // Skip types that has no public empty constructors (activator can not create them)
if (type.IsClass && type.GetConstructor(Type.EmptyTypes) == null) // Structs still can be created (strangely) if (type.IsClass && type.GetConstructor(Type.EmptyTypes) == null) // Structs still can be created (strangely)