mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
use the required binding flags for the copy constructor too
This commit is contained in:
parent
500025090f
commit
99a49c6c81
1 changed files with 2 additions and 2 deletions
|
@ -86,12 +86,12 @@ namespace MLEM.Data {
|
||||||
|
|
||||||
private static object Construct(Type t, BindingFlags flags) {
|
private static object Construct(Type t, BindingFlags flags) {
|
||||||
// find a contructor with the correct attribute
|
// 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
|
// fall back to a parameterless constructor
|
||||||
if (constructor == null)
|
if (constructor == null)
|
||||||
constructor = t.GetConstructor(flags, null, Type.EmptyTypes, null);
|
constructor = t.GetConstructor(flags, null, Type.EmptyTypes, null);
|
||||||
if (constructor == 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]);
|
return constructor.Invoke(new object[constructor.GetParameters().Length]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue