Skip to content

Commit

Permalink
Fixes critical issue with nesting on BSDataGrid property Mapper. Nest…
Browse files Browse the repository at this point in the history
…ed classes caused a stack overflow. So same class types are now Only limited to a depth of 4.
  • Loading branch information
jbomhold3 committed Oct 14, 2024
1 parent 9e9319c commit 8a1f456
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/BlazorStrap/BlazorStrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://blazorstrap.io/</PackageProjectUrl>
<RepositoryUrl>https://github.com/chanan/BlazorStrap</RepositoryUrl>
<RootNamespace>BlazorStrap</RootNamespace>
<PackageVersion>5.2.103-Beta2</PackageVersion>
<PackageVersion>5.2.103-Beta2a</PackageVersion>
<AnalysisLevel>6.0</AnalysisLevel><!--Next Use 5.2.200-Preview1-->
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ public static ICollection<string> GetPropertyPaths<TGridItem>()
return GetPropertyPathRecursive(typeof(TGridItem));
}
// Recursive method that handles property path generation
private static ICollection<string> GetPropertyPathRecursive(Type type, string parentPath = "", bool isRoot = true)
private static ICollection<string> GetPropertyPathRecursive(Type type, string parentPath = "", bool isRoot = true, int depth = 0, Type? parentType = null)
{
if (parentType == type) depth++;
if(depth > 3) return new List<string>();
List<string> propertyPaths = new List<string>();
// 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)
Expand All @@ -78,7 +82,8 @@ private static ICollection<string> GetPropertyPathRecursive(Type type, string pa
continue;
}
// Use reflection to invoke the method recursively with the property type
ICollection<string> nestedPaths = GetPropertyPathRecursive(property.PropertyType, propertyPath, false);
parentType = type;
ICollection<string> nestedPaths = GetPropertyPathRecursive(property.PropertyType, propertyPath, false, depth, parentType);
propertyPaths.AddRange(nestedPaths);
}
}
Expand Down

0 comments on commit 8a1f456

Please sign in to comment.