-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make PropertySetter a concrete type #25054
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,55 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Reflection; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.Reflection | ||
| { | ||
| internal interface IPropertySetter | ||
| internal sealed class PropertySetter | ||
| { | ||
| bool Cascading { get; } | ||
| private static readonly MethodInfo CallPropertySetterOpenGenericMethod = | ||
| typeof(PropertySetter).GetMethod(nameof(CallPropertySetter), BindingFlags.NonPublic | BindingFlags.Static)!; | ||
|
|
||
| private readonly Action<object, object> _setterDelegate; | ||
|
|
||
| public PropertySetter(Type targetType, PropertyInfo property) | ||
| { | ||
| if (property.SetMethod == null) | ||
| { | ||
| throw new InvalidOperationException($"Cannot provide a value for property " + | ||
| $"'{property.Name}' on type '{targetType.FullName}' because the property " + | ||
| $"has no setter."); | ||
| } | ||
|
|
||
| var setMethod = property.SetMethod; | ||
|
|
||
| var propertySetterAsAction = | ||
| setMethod.CreateDelegate(typeof(Action<,>).MakeGenericType(targetType, property.PropertyType)); | ||
| var callPropertySetterClosedGenericMethod = | ||
| CallPropertySetterOpenGenericMethod.MakeGenericMethod(targetType, property.PropertyType); | ||
| _setterDelegate = (Action<object, object>) | ||
| callPropertySetterClosedGenericMethod.CreateDelegate(typeof(Action<object, object>), propertySetterAsAction); | ||
| } | ||
|
|
||
| public bool Cascading { get; init; } | ||
|
|
||
| public void SetValue(object target, object value) => _setterDelegate(target, value); | ||
|
|
||
| void SetValue(object target, object value); | ||
| private static void CallPropertySetter<TTarget, TValue>( | ||
| Action<TTarget, TValue> setter, | ||
| object target, | ||
| object value) | ||
| where TTarget : notnull | ||
| { | ||
| if (value == null) | ||
| { | ||
| setter((TTarget)target, default!); | ||
| } | ||
| else | ||
| { | ||
| setter((TTarget)target, (TValue)value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project> | ||
| <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- Makes our docker composition simpler by not redirecting build and publish output to the artifacts dir --> | ||
| <BaseIntermediateOutputPath /> | ||
| <IntermediateOutputPath /> | ||
| <BaseOutputPath /> | ||
| <OutputPath /> | ||
| </PropertyGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,7 @@ class Selenium | |
| const int SeleniumPort = 4444; | ||
| static bool RunHeadlessBrowser = true; | ||
|
|
||
| static bool PoolForBrowserLogs = | ||
| #if DEBUG | ||
| true; | ||
| #else | ||
| false; | ||
| #endif | ||
| static bool PoolForBrowserLogs = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. We had it turned off because running the benchmarks would bury you logs from the GC. But that's all gone now and it actually helps to see the benchmark progress when you're running it in a container. |
||
|
|
||
| private static async ValueTask<Uri> WaitForServerAsync(int port, CancellationToken cancellationToken) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is identical to what PropertyHelper does: https://github.com/dotnet/aspnetcore/blob/master/src/Shared/PropertyHelper/PropertyHelper.cs#L312-L321. I wasn't sure if we intentionally avoided using that type in here for some reason, so I copied it over. It avoids a Activator.CreateInstance call that we previously had per property which would be an improvement in my books