From 761176e097e6040016f9187c9cd9166f45c51004 Mon Sep 17 00:00:00 2001 From: Edward Miller Date: Fri, 29 Dec 2023 02:55:13 -0600 Subject: [PATCH] avoid delegate creation --- Maui.DataGrid/Extensions/ReflectionExtensions.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Maui.DataGrid/Extensions/ReflectionExtensions.cs b/Maui.DataGrid/Extensions/ReflectionExtensions.cs index 3582768..6206da9 100644 --- a/Maui.DataGrid/Extensions/ReflectionExtensions.cs +++ b/Maui.DataGrid/Extensions/ReflectionExtensions.cs @@ -45,7 +45,13 @@ internal static class ReflectionExtensions private static object? GetPropertyValue(object obj, string propertyName) { - var properties = PropertyTypeCache.GetOrAdd(obj.GetType(), _ => TypeDescriptor.GetProperties(obj)); + var type = obj.GetType(); + + if (!PropertyTypeCache.TryGetValue(type, out var properties)) + { + properties = TypeDescriptor.GetProperties(obj); + PropertyTypeCache[type] = properties; + } var propertyDescriptor = properties.Find(propertyName, false);