1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-28 19:13:38 +02:00

use the required binding flags for the copy constructor too

This commit is contained in:
Ell 2020-10-25 20:16:10 +01:00
parent 500025090f
commit 99a49c6c81

View file

@ -86,12 +86,12 @@ namespace MLEM.Data {
private static object Construct(Type t, BindingFlags flags) {
// find a contructor with the correct attribute
var constructor = t.GetConstructors().FirstOrDefault(c => c.GetCustomAttribute<CopyConstructorAttribute>() != null);
var constructor = t.GetConstructors(flags).FirstOrDefault(c => c.GetCustomAttribute<CopyConstructorAttribute>() != null);
// fall back to a parameterless constructor
if (constructor == null)
constructor = t.GetConstructor(flags, null, Type.EmptyTypes, null);
if (constructor == null)
throw new NullReferenceException($"Type {t} does not have a parameterless constructor with the required visibility or a constructor with the CopyConstructorAttribute");
throw new NullReferenceException($"Type {t} does not have a parameterless constructor or a constructor with the CopyConstructorAttribute with the required visibility");
return constructor.Invoke(new object[constructor.GetParameters().Length]);
}