From 99a49c6c81f2c3d479b9f774f877e5f3f9fe1d34 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 25 Oct 2020 20:16:10 +0100 Subject: [PATCH] use the required binding flags for the copy constructor too --- MLEM.Data/CopyExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MLEM.Data/CopyExtensions.cs b/MLEM.Data/CopyExtensions.cs index 1c2064f..aa43cd0 100644 --- a/MLEM.Data/CopyExtensions.cs +++ b/MLEM.Data/CopyExtensions.cs @@ -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() != null); + var constructor = t.GetConstructors(flags).FirstOrDefault(c => c.GetCustomAttribute() != 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]); }