Skip to content

Commit 8a1f456

Browse files
committed
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.
1 parent 9e9319c commit 8a1f456

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/BlazorStrap/BlazorStrap.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<PackageProjectUrl>https://blazorstrap.io/</PackageProjectUrl>
1414
<RepositoryUrl>https://github.com/chanan/BlazorStrap</RepositoryUrl>
1515
<RootNamespace>BlazorStrap</RootNamespace>
16-
<PackageVersion>5.2.103-Beta2</PackageVersion>
16+
<PackageVersion>5.2.103-Beta2a</PackageVersion>
1717
<AnalysisLevel>6.0</AnalysisLevel><!--Next Use 5.2.200-Preview1-->
1818
</PropertyGroup>
1919

src/BlazorStrap/Shared/Components/DataGrid/ExpressionHelper.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ public static ICollection<string> GetPropertyPaths<TGridItem>()
5757
return GetPropertyPathRecursive(typeof(TGridItem));
5858
}
5959
// Recursive method that handles property path generation
60-
private static ICollection<string> GetPropertyPathRecursive(Type type, string parentPath = "", bool isRoot = true)
60+
private static ICollection<string> GetPropertyPathRecursive(Type type, string parentPath = "", bool isRoot = true, int depth = 0, Type? parentType = null)
6161
{
62+
if (parentType == type) depth++;
63+
if(depth > 3) return new List<string>();
6264
List<string> propertyPaths = new List<string>();
6365
// Reflect only public instance properties
6466
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
6567

6668
foreach (PropertyInfo property in properties)
6769
{
70+
6871
string propertyPath = isRoot ? property.Name : $"{parentPath}.{property.Name}";
72+
6973
propertyPaths.Add(propertyPath);
7074

7175
// Check if the property is a class but not string, or a struct (non-primitive)
@@ -78,7 +82,8 @@ private static ICollection<string> GetPropertyPathRecursive(Type type, string pa
7882
continue;
7983
}
8084
// Use reflection to invoke the method recursively with the property type
81-
ICollection<string> nestedPaths = GetPropertyPathRecursive(property.PropertyType, propertyPath, false);
85+
parentType = type;
86+
ICollection<string> nestedPaths = GetPropertyPathRecursive(property.PropertyType, propertyPath, false, depth, parentType);
8287
propertyPaths.AddRange(nestedPaths);
8388
}
8489
}

0 commit comments

Comments
 (0)