Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 16 additions & 29 deletions src/Shared/ActivatorUtilities/ActivatorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,30 @@ public static object CreateInstance(IServiceProvider provider, Type instanceType
{
foreach (var constructor in instanceType.GetConstructors())
{
if (!constructor.IsStatic)
{
var matcher = new ConstructorMatcher(constructor);
var isPreferred = constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), false);
var length = matcher.Match(parameters);
var matcher = new ConstructorMatcher(constructor);
var isPreferred = constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), false);
var length = matcher.Match(parameters);

if (isPreferred)
if (isPreferred)
{
if (seenPreferred)
{
if (seenPreferred)
{
ThrowMultipleCtorsMarkedWithAttributeException();
}

if (length == -1)
{
ThrowMarkedCtorDoesNotTakeAllProvidedArguments();
}
ThrowMultipleCtorsMarkedWithAttributeException();
}

if (isPreferred || bestLength < length)
if (length == -1)
{
bestLength = length;
bestMatcher = matcher;
ThrowMarkedCtorDoesNotTakeAllProvidedArguments();
}
}

seenPreferred |= isPreferred;
if (isPreferred || bestLength < length)
{
bestLength = length;
bestMatcher = matcher;
}

seenPreferred |= isPreferred;
}
}

Expand Down Expand Up @@ -237,11 +234,6 @@ private static bool TryFindMatchingConstructor(
{
foreach (var constructor in instanceType.GetConstructors())
{
if (constructor.IsStatic)
{
continue;
}

if (TryCreateParameterMap(constructor.GetParameters(), argumentTypes, out int?[] tempParameterMap))
{
if (matchingConstructor != null)
Expand All @@ -267,11 +259,6 @@ private static bool TryFindPreferredConstructor(
var seenPreferred = false;
foreach (var constructor in instanceType.GetConstructors())
{
if (constructor.IsStatic)
{
continue;
}

if (constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), false))
{
if (seenPreferred)
Expand Down