From 8a1f456d962377677be34f202f4973162a9e2ecd Mon Sep 17 00:00:00 2001 From: John Bomhold Date: Sun, 13 Oct 2024 23:11:56 -1000 Subject: [PATCH] Fixes critical issue with nesting on BSDataGrid property Mapper. Nested classes caused a stack overflow. So same class types are now Only limited to a depth of 4. --- src/BlazorStrap/BlazorStrap.csproj | 2 +- .../Shared/Components/DataGrid/ExpressionHelper.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/BlazorStrap/BlazorStrap.csproj b/src/BlazorStrap/BlazorStrap.csproj index 6ce239ad..adcddc26 100644 --- a/src/BlazorStrap/BlazorStrap.csproj +++ b/src/BlazorStrap/BlazorStrap.csproj @@ -13,7 +13,7 @@ https://blazorstrap.io/ https://github.com/chanan/BlazorStrap BlazorStrap - 5.2.103-Beta2 + 5.2.103-Beta2a 6.0 diff --git a/src/BlazorStrap/Shared/Components/DataGrid/ExpressionHelper.cs b/src/BlazorStrap/Shared/Components/DataGrid/ExpressionHelper.cs index 8365bce1..434d5a82 100644 --- a/src/BlazorStrap/Shared/Components/DataGrid/ExpressionHelper.cs +++ b/src/BlazorStrap/Shared/Components/DataGrid/ExpressionHelper.cs @@ -57,15 +57,19 @@ public static ICollection GetPropertyPaths() return GetPropertyPathRecursive(typeof(TGridItem)); } // Recursive method that handles property path generation - private static ICollection GetPropertyPathRecursive(Type type, string parentPath = "", bool isRoot = true) + private static ICollection GetPropertyPathRecursive(Type type, string parentPath = "", bool isRoot = true, int depth = 0, Type? parentType = null) { + if (parentType == type) depth++; + if(depth > 3) return new List(); List propertyPaths = new List(); // Reflect only public instance properties PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo property in properties) { + string propertyPath = isRoot ? property.Name : $"{parentPath}.{property.Name}"; + propertyPaths.Add(propertyPath); // Check if the property is a class but not string, or a struct (non-primitive) @@ -78,7 +82,8 @@ private static ICollection GetPropertyPathRecursive(Type type, string pa continue; } // Use reflection to invoke the method recursively with the property type - ICollection nestedPaths = GetPropertyPathRecursive(property.PropertyType, propertyPath, false); + parentType = type; + ICollection nestedPaths = GetPropertyPathRecursive(property.PropertyType, propertyPath, false, depth, parentType); propertyPaths.AddRange(nestedPaths); } }