Skip to content

Commit

Permalink
fix: Fixes check for private ctor during instance creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kali-Sh committed Sep 12, 2023
1 parent 6cb3fb3 commit bb7aaa0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Elders.Cronus/Userfull/FastActivator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down Expand Up @@ -68,8 +69,8 @@ public static object CreateInstance(Type type, bool @private, params object[] ar
ObjectActivator activator;
if (!activators.TryGetValue(type, out activator))
{
var constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic);
if (constructors.Length == 1)
IEnumerable<ConstructorInfo> constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).Where(ctor => ctor.GetParameters().Length == 0);
if (constructors.Any())
{
ConstructorInfo ctor = constructors.First();
activator = GetActivator(ctor);
Expand All @@ -84,4 +85,4 @@ public static object CreateInstance(Type type, bool @private, params object[] ar
return activator(args);
}
}
}
}

0 comments on commit bb7aaa0

Please sign in to comment.