Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivatorUtilities: Do not wrap Delegate.Invoke in another delegate #105814

Merged
merged 2 commits into from
Aug 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ public static ObjectFactory CreateFactory(
#endif
CreateFactoryInternal(instanceType, argumentTypes, out ParameterExpression provider, out ParameterExpression argumentArray, out Expression factoryExpressionBody);

var factoryLambda = Expression.Lambda<Func<IServiceProvider, object?[]?, object>>(
var factoryLambda = Expression.Lambda<ObjectFactory>(
factoryExpressionBody, provider, argumentArray);

Func<IServiceProvider, object?[]?, object>? result = factoryLambda.Compile();
return result.Invoke;
ObjectFactory? result = factoryLambda.Compile();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for other reviewers: ObjectFactory delegate is declared here:

public delegate object ObjectFactory(IServiceProvider serviceProvider, object?[]? arguments);

return result;
}

/// <summary>
Expand Down Expand Up @@ -324,11 +324,11 @@ public static ObjectFactory<T>
#endif
CreateFactoryInternal(typeof(T), argumentTypes, out ParameterExpression provider, out ParameterExpression argumentArray, out Expression factoryExpressionBody);

var factoryLambda = Expression.Lambda<Func<IServiceProvider, object?[]?, T>>(
var factoryLambda = Expression.Lambda<ObjectFactory<T>>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

factoryExpressionBody, provider, argumentArray);

Func<IServiceProvider, object?[]?, T>? result = factoryLambda.Compile();
return result.Invoke;
ObjectFactory<T>? result = factoryLambda.Compile();
return result;
}

private static void CreateFactoryInternal([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type instanceType, Type[] argumentTypes, out ParameterExpression provider, out ParameterExpression argumentArray, out Expression factoryExpressionBody)
Expand Down
Loading