Skip to content

Commit 9b83357

Browse files
committed
Make the linker happy
1 parent 146e9d0 commit 9b83357

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/Components/Components/src/SupplyParameterFromPersistentComponentStateValueProvider.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.Diagnostics.CodeAnalysis;
88
using System.Globalization;
9+
using System.Reflection;
910
using System.Security.Cryptography;
1011
using System.Text;
1112
using Microsoft.AspNetCore.Components.Reflection;
@@ -76,18 +77,23 @@ public void Subscribe(ComponentState subscriber, in CascadingParameterInfo param
7677
}, subscriber.Renderer.GetComponentRenderMode(subscriber.Component));
7778
}
7879

79-
private static PropertyGetter ResolvePropertyGetter([DynamicallyAccessedMembers(LinkerFlags.Component)] Type type, string propertyName)
80+
private static PropertyGetter ResolvePropertyGetter(Type type, string propertyName)
8081
{
81-
return _propertyGetterCache.GetOrAdd((type, propertyName), (key) =>
82+
return _propertyGetterCache.GetOrAdd((type, propertyName), PropertyGetterFactory);
83+
}
84+
85+
private static PropertyGetter PropertyGetterFactory((Type type, string propertyName) key)
86+
{
87+
var (type, propertyName) = key;
88+
var propertyInfo = GetPropertyInfo(type, propertyName);
89+
if (propertyInfo == null)
8290
{
83-
var (type, propertyName) = key;
84-
var propertyInfo = type.GetProperty(propertyName);
85-
if (propertyInfo == null)
86-
{
87-
throw new InvalidOperationException($"Property {propertyName} not found on type {type.FullName}");
88-
}
89-
return new PropertyGetter(type, propertyInfo);
90-
});
91+
throw new InvalidOperationException($"Property {propertyName} not found on type {type.FullName}");
92+
}
93+
return new PropertyGetter(type, propertyInfo);
94+
95+
static PropertyInfo? GetPropertyInfo([DynamicallyAccessedMembers(LinkerFlags.Component)] Type type, string propertyName)
96+
=> type.GetProperty(propertyName);
9197
}
9298

9399
public void Unsubscribe(ComponentState subscriber, in CascadingParameterInfo parameterInfo)

0 commit comments

Comments
 (0)